Articles in this section
Category / Section

How to move the contents of WinForms GridGroupingControl to Excel?

1 min read

Exporting

You can move the contents of the GridGroupingControl to Excel by using GroupingGridToExcel method in GroupingGridExcelConverterControl class.

C#

private void btnExport_Click(object sender, EventArgs e)
{
   Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();
   SaveFileDialog saveFileDialog = new SaveFileDialog();
   saveFileDialog.Filter = "Files(*.xls)|*.xls";
   saveFileDialog.DefaultExt = ".xls";
   if(saveFileDialog.ShowDialog() == DialogResult.OK)
   {
      //Export Grid by using GridToExcel method.
      gecc.GridToExcel(this.gridGroupingControl1.Table.TableModel, saveFileDialog.FileName,
      Syncfusion.GridExcelConverter.ConverterOptions.Default);
      if(MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      {
         Process proc = new Process();
         proc.StartInfo.FileName = saveFileDialog.FileName;
         proc.Start();
      }
   }
}

VB

Private Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs)
   Dim gecc As New Syncfusion.GridExcelConverter.GridExcelConverterControl()
   Dim saveFileDialog As New SaveFileDialog()
   saveFileDialog.Filter = "Files(*.xls)|*.xls"
   saveFileDialog.DefaultExt = ".xls"
   If saveFileDialog.ShowDialog() = DialogResult.OK Then
      'Export Grid by using GridToExcel method.
      gecc.GridToExcel(Me.gridGroupingControl1.Table.TableModel, saveFileDialog.FileName, Syncfusion.GridExcelConverter.ConverterOptions.Default)
      If MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
         Dim proc As New Process()
         proc.StartInfo.FileName = saveFileDialog.FileName
         proc.Start()
      End If
   End If
End Sub

Screenshot

GridGroupingControl with data source

Figure 1: GridGroupingControl with DataSource.

Show GridGroupingControl values after exporting to excel

Figure 2: GridGroupingControl Values after exporting to Excel.

Samples:

C#: ExportToExcel-C#

VB: ExportToExcel-VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/exporting

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