2016-02-26 1 views
0

J'exporte mon radgridview à excel. mon problème est de savoir comment puis-je ajouter un haut frontière sur une cellule ... Je suis vraiment nouveau à cela alors s'il vous plaît garder avec moi ...Excel: Ajouter Bordure Top sur Cellule ....

J'ai essayé d'utiliser ce code .Borders[Excel.XlBordersIndex.xlEdgeTop].Weight = 1d; mais ne peut toujours pas faire le bordertop sur excel cell .....

merci d'avance.

 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; 

     } 

Répondre

0

Celui-ci a fonctionné pour moi

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;