Category / Section
How to export the multiple SfDataGrid's to single excel sheet?
1 min read
In SfDataGrid control, you can export data to Excel by using the ExportToExcel method. If you want export multiple SfDataGrid’s to single excel sheet , you need to merge the one SfDataGrid WorkSheet into another SfDataGrid WorkSheet using Worksheet.UsedRange.CopyTo method like the below code example.
C#
using Syncfusion.UI.Xaml.Grid.Converter; using Syncfusion.XlsIO;try { var options = new ExcelExportingOptions(); options.ExcelVersion = ExcelVersion.Excel2010; var excelEngine = dataGrid1.ExportToExcel(dataGrid1.View, options); var workBook1 = excelEngine.Excel.Workbooks[0]; var worksheet1 = workBook1.Worksheets[0]; excelEngine = dataGrid2.ExportToExcel(dataGrid2.View, options); var workBook2 = excelEngine.Excel.Workbooks[0]; var worksheet2 = workBook2.Worksheets[0]; var columnCount = dataGrid1.Columns.Count; //Merge the One SfDataGrid WorkSheet into the other SfDataGrid WorkSheet worksheet2.UsedRange.CopyTo(worksheet1[1, columnCount + 1]); workBook1.SaveAs("sample.xlsx"); } catch (Exception) { }
Samples: