)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export different data of two grids simultaneously into one excel sheet in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: February 9, 2015 |
Last Revised Date: December 23, 2019
Tags: exporting

Excel export

Exporting more than one data source data in GridGroupingControl can be simultaneously performed while exporting the Grid to Excel by using the ImportDataTable method. Using this method, you can merge more than one data table from Grid to Excel. In worksheet, you can add more than one data table and save the sheet to workbook in Excel.

C#

private void export_Click(object sender, EventArgs e)
{
   SaveFileDialog saveFileDialog = new SaveFileDialog();
   saveFileDialog.Filter = "Files(*.XLS)|*.XLS";
   saveFileDialog.AddExtension = true;
   saveFileDialog.DefaultExt = ".XLS";
   this.gridGroupingControl1.ShowRowHeaders = false;
   // Export Grid to Excel
   GroupingGridExcelConverterControl converter = new GroupingGridExcelConverterControl();
   ExcelEngine Engine = new ExcelEngine();
   IWorkbook workbook = Engine.Excel.Workbooks.Create(1);
   IWorksheet sheet = workbook.Worksheets[0];
   sheet.Name = "sample";
   // Export GridGroupingcontrol 1 and 2 to excel sheet
   sheet.ImportDataTable(dt, true, 1, 1);
   sheet.ImportDataTable(dts, true, 1, 9);
   // save to workbook in excel
   workbook.SaveAs("Sample.xls");
   Process.Start("Sample.xls");
}

VB

Private Sub export_Click (ByVal sender As Object, ByVal e As EventArgs) Handles export_Click
   Dim saveFileDialog As New SaveFileDialog()
   saveFileDialog.Filter = "Files(*.XLS)|*.XLS"
   saveFileDialog.AddExtension = True
   saveFileDialog.DefaultExt = ".XLS"
   Me.gridGroupingControl1.ShowRowHeaders = False
   ' Export Grid to Excel
   Dim converter As New GroupingGridExcelConverterControl()
   Dim Engine As New ExcelEngine()
   Dim workbook As IWorkbook = Engine.Excel.Workbooks.Create(1)
   Dim sheet As IWorksheet = workbook.Worksheets(0)
   sheet.Name = "sample"
   ' Export GridGroupingcontrol 1 and 2 to excel sheet
   sheet.ImportDataTable(dt, True, 1, 1)
   sheet.ImportDataTable(dts, True, 1, 9)
   ' save to workbook in excel
   workbook.SaveAs("Sample.xls")
   Process.Start("Sample.xls")
End Sub

Samples:

C#: ExportToExcel CS

VB: ExportToExcel VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/exporting

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon