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

How to export two grids in a single worksheet of a workbook in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl

Excel export

By default, the GridGroupingControl does not have direct support to export multiple grids as same as in view (with styles and formats) into a single worksheet in the workbook. To perform this, create a custom GridGroupingExcelConverterControl class. Set proper value to the ExcelStartRowIndex property of the worksheet in the ExportTable overridden method.


//Creating custom class
public class GridGroupingExcelConverterControlEXT: GridGroupingExcelConverterControl
    private int rowIndex = 1;
    public GridGroupingExcelConverterControlEXT()
    public int ExcelStartRowIndex { get { return rowIndex; } set{ rowIndex = value; } }
    protected override void ExportTable(IList tableElements, GridTableDescriptor tableDescriptor, ref int excelRowIndex, int excelStartColumnIndex,bool isNestedTable,IWorksheet sheet,ExcelExportingOptions exportingOptions)
        excelRowIndex = ExcelStartRowIndex;
        base.ExportTable(tableElements, tableDescriptor, ref excelRowIndex, excelStartColumnIndex, isNestedTable, sheet, exportingOptions);
//Exporting to Excel
private void exportBtn_Click(object sender, EventArgs e)
    ExcelEngine Engine = new ExcelEngine();
    IWorkbook workbook = Engine.Excel.Workbooks.Create(1);
    IWorksheet sheet = workbook.Worksheets[0];
    sheet.Name = "sample";                    
    ExcelExportingOptions options = new ExcelExportingOptions();
    GridGroupingExcelConverterControlEXT converter = new GridGroupingExcelConverterControlEXT();
    //Exporting 1st grid
    converter.ExportToExcel(gridGroupingControl1, sheet, options);
    //Specifying the starting row index of 2nd grid
    converter.ExcelStartRowIndex = sheet.UsedRange.LastRow + 2;
    //Exporting 2nd grid
    converter.ExportToExcel(gridGroupingControl2, sheet, options);



'Creating custom class 
Public Class GridGroupingExcelConverterControlEXT
     Inherits GridGroupingExcelConverterControl
     Private rowIndex As Integer = 1
     Public Sub New()
     End Sub
     Public Property ExcelStartRowIndex() As Integer
 Return rowIndex
         End Get
         Set(ByVal value As Integer)
 rowIndex = value
         End Set
     End Property
     Protected Overrides Sub ExportTable(ByVal tableElements As IList, ByVal tableDescriptor As GridTableDescriptor, ByRef excelRowIndex As Integer, ByVal excelStartColumnIndex As Integer, ByVal isNestedTable As Boolean, ByVal sheet As IWorksheet, ByVal exportingOptions As ExcelExportingOptions)
          excelRowIndex = ExcelStartRowIndex
          MyBase.ExportTable(tableElements, tableDescriptor, excelRowIndex, excelStartColumnIndex, isNestedTable, sheet, exportingOptions)
     End Sub
End Class
'Exporting to Excel
Private Sub exportBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles exportBtn.Click
     Dim Engine As New ExcelEngine()
     Dim workbook As IWorkbook = Engine.Excel.Workbooks.Create(1)
     Dim sheet As IWorksheet = workbook.Worksheets(0)
     sheet.Name = "sample"
     ' save to workbook in excel
     Dim options As New ExcelExportingOptions()
     Dim converter As New GridGroupingExcelConverterControlEXT()
    ‘Exporting 1st grid
    converter.ExportToExcel(gridGroupingControl1, sheet, options)
    ‘Specifying the starting row index of 2nd grid
    converter.ExcelStartRowIndex = sheet.UsedRange.LastRow + 2
    ‘Exporting 2nd grid
    converter.ExportToExcel(gridGroupingControl2, sheet, options)
End Sub



Export multiple grids

Export GridGroupingControl to Excel sheet



C#: Export multiple grid_CS

VB: Export multiple grid_VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/exporting#excel-export

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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