How to export multi SfDataGrid View to One Excel file with diffrent worksheet?

Hello

I have multi SfDataGrid view  try to use ExcelEngine to export in one Excel file but each SfDataGrid data on one worksheet like this. Is that possible

thanks.

Image_5586_1707376122381

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

1 Reply

CM Chidanand Murugaiah Syncfusion Team February 9, 2024 09:44 AM UTC

Hi Johnes,


Your requirement of "Exporting multiple datagrid in a single excel file" can be mentioning the worksheet number while calling the ExportToExcel method. We prepared a sample and attached with this response for your reference.

Kindly refer the below code snippet

var options = new ExcelExportingOptions();

 options.ExcelVersion = ExcelVersion.Excel2013;

 ExcelEngine excelEngine = new ExcelEngine();

 IWorkbook workBook = excelEngine.Excel.Workbooks.Create();

 dataGrid.ExportToExcel(dataGrid.View, options, workBook.Worksheets[0]);

 dataGrid1.ExportToExcel(dataGrid1.View, options, workBook.Worksheets[1]);

 workBook.SaveAs("Sample.xlsx");

You can also refer our online user guide documentation regarding the same by the following link and also we have attached the sample for your reference.


UG linkhttps://help.syncfusion.com/wpf/datagrid/export-to-excel#worksheet-customization


We hope this helps. Please let us know, if need any further assistance.


Regards,

Chidanand M.


Attachment: SfDataGrid_Demo4_8_bf3ce7a9.zip

Loader.
Up arrow icon