We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is it possible to set Cell Borders when exporting to excel?

As stated in the subject,

using your samples I've been able to format many things on  columns and cells when exporting to excel a SFDatagrid, but I haven't been able to find a way to set the cell borders and the column widths.

is there a way to do so using the events and/or the cell styling? or setting something to copy the cell borders from the grid itself?

thank you in advance
Regards
Sabrina


1 Reply

JG Jai Ganesh S Syncfusion Team January 6, 2016 01:04 PM UTC

Hi Sabrina,

You can apply the cell borders for whole sheet when Export to Excel by using the below code example,

Code Example:

 var excelEngine = dataGrid.ExportToExcel(dataGrid.View, options);

               

 // Gets the exported workbook from the ExcelEngine

 var workBook = excelEngine.Excel.Workbooks[0];

 IWorksheet worksheet = workBook.Worksheets[0];


 worksheet.UsedRange.CellStyle.Borders.LineStyle = ExcelLineStyle.Thick;


Also you can apply the border for particular cell by using the below code example,

Code Example:

  var excelEngine = dataGrid.ExportToExcel(dataGrid.View, options);

               

 // Gets the exported workbook from the ExcelEngine

 var workBook = excelEngine.Excel.Workbooks[0];

 IWorksheet worksheet = workBook.Worksheets[0];


 
 worksheet.Range["C6"].CellStyle.Borders.LineStyle = ExcelLineStyle.Medium_dash_dot_dot;


You can set the column width for the Exported datas by using the below code example,

Set Column width for all columns in a page


worksheet.UsedRange.ColumnWidth = 40;


Set Column width for particular column

worksheet.UsedRange.Columns[1].ColumnWidth = 15;


Sample: http://www.syncfusion.com/downloads/support/directtrac/148666/ze/ExportExcel1370829987

Ug Link:
http://help.syncfusion.com/file-formats/xlsio/working-with-cell-or-range-formatting#apply-border-settings

Regards,
Jai Ganesh S

Loader.
Up arrow icon