Articles in this section

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

Excel export


Exporting more than one data source in WinForms GridGroupingControl can be performed simultaneously with 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 a worksheet, you can add more than one data table and save the sheet to a 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: Exporting

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied