2016-02-26 161 views
0

我正在將我的radgridview導出到excel。我的問題是我怎麼才能在單元格上添加邊框頂端...我真的很新,所以請耐心等待...Excel:在單元格中添加邊框頂部....

我試過使用此代碼.Borders[Excel.XlBordersIndex.xlEdgeTop].Weight = 1d;但仍不能對bordertop執行操作excel cell .....

在此先感謝。

 foreach (GridViewSummaryRowInfo item in gridviewID.MasterView.SummaryRows) 
     { 
      objexcelapp.Cells[lastRow + 3, 4] = item.Cells[item.Index + 4].Value.ToString(); 
      objexcelapp.Cells[lastRow + 3, 5] = item.Cells[item.Index + 5].Value.ToString(); 
      objexcelapp.Cells[lastRow + 3, 4].Font.Bold = true; 
      objexcelapp.Cells[lastRow + 3, 5].Font.Bold = true; 

     } 

回答

0

這一個爲我工作

Excel.Range range = sheet.UsedRange; 
Excel.Range cell = range.Cells[1][1]; 
Excel.Borders border = cell.Borders; 
border[XlBordersIndex.xlEdgeLeft].LineStyle = 
    Excel.XlLineStyle.xlContinuous; 
border[XlBordersIndex.xlEdgeTop].LineStyle = 
    Excel.XlLineStyle.xlContinuous; 
border[XlBordersIndex.xlEdgeBottom].LineStyle = 
    Excel.XlLineStyle.xlContinuous; 
border[XlBordersIndex.xlEdgeRight].LineStyle = 
    Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; 
相關問題