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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

121593 Jan 5,2016 01:09 PM Jan 6,2016 08:04 AM WPF 1
loading
Tags: SfDataGrid
sabrina c.
Asked On January 5, 2016 01:09 PM

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


Jai Ganesh S [Syncfusion]
Replied On January 6, 2016 08:04 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;