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 the grid with customized background to excel in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 19, 2015 |
Last Revised Date: February 14, 2020
Tags: exporting

Exporting

The customizing color elements such as borders, back color, etc., and data are exported from the GridGroupingControl into an Excel sheet for which you can use the GroupingGridToExcel method in the GroupingGridExcelConverterControl Class. The SaveFileDialog Class prompts you to select the location for saving a file.

C#

private void bt_export_Click(object sender, System.EventArgs e)
{
   SaveFileDialog saveFileDialog = new SaveFileDialog();
   saveFileDialog.Filter = "Files(*.XLS)|*.XLS";
   saveFileDialog.AddExtension = true;
   saveFileDialog.DefaultExt = ".XLS";
   if(saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.CheckPathExists)
   {
      GroupingGridExcelConverterControl converter = new GroupingGridExcelConverterControl();
      //ExportStyle
      converter.ExportBorders = true;
      //set the backcolor of the header
      converter.HeaderBackColor = Color.Aqua;
      //set the backcolor of the caption
      converter.CaptionBackColor = Color.MistyRose;
      converter.ExportPreviewRows = true;
      //export the plus/minus icons
      converter.ExportGroupPlusMinus = true;
      converter.ExportRecordPlusMinus = true;
      ConverterOptions options = ConverterOptions.Default;
      converter.GroupingGridToExcel(this.gridGroupingControl1, saveFileDialog.FileName, options);
      converter.Dispose();
      if(MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      {
         System.Diagnostics.Process proc = new System.Diagnostics.Process();
         proc.StartInfo.FileName = saveFileDialog.FileName;
         proc.Start();
      }
   }
}

VB

Private Sub bt_export_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   Dim saveFileDialog As New SaveFileDialog()
   saveFileDialog.Filter = "Files(*.XLS)|*.XLS"
   saveFileDialog.AddExtension = True
   saveFileDialog.DefaultExt = ".XLS"
   If saveFileDialog.ShowDialog() = DialogResult.OK AndAlso saveFileDialog.CheckPathExists Then
     Dim converter As New GroupingGridExcelConverterControl()
     'ExportStyle
     converter.ExportBorders = True
     'set the backcolor of the header
     converter.HeaderBackColor = Color.Aqua
     'set the backcolor of the caption
     converter.CaptionBackColor = Color.MistyRose
     converter.ExportPreviewRows = True
     'export the plus/minus icons
     converter.ExportGroupPlusMinus = True
     converter.ExportRecordPlusMinus = True
     Dim options As ConverterOptions = ConverterOptions.Default
     converter.GroupingGridToExcel(Me.gridGroupingControl1, saveFileDialog.FileName, options)
     converter.Dispose()
     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 System.Diagnostics.Process()
        proc.StartInfo.FileName = saveFileDialog.FileName
        proc.Start()
     End If
  End If
End Sub

Samples:

C#: Export

VB: Export

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