ComponentOne True DBGrid for WinForms
Exporting to Excel
True DBGrid for WinForms Task-Based Help > Exporting Grid Data > Exporting to Excel

TrueDBGrid allows exporting grid data to Microsoft Excel format by using either of the following methods:

It is important to note that time taken to export grid data to Excel format is very small when using the SaveExcel method. In comparison, the ExportToExcel method takes much longer to export data.

SaveExcel method

To set the SaveExcel method, add the following code to the Click event of the Export button:

To write code in Visual Basic

Visual Basic
Copy Code
Me.c1TrueDBGrid1.SaveExcel("../../GridData.xlsx")

To write code in C#

C#
Copy Code
this.c1TrueDBGrid1.SaveExcel("../../GridData.xlsx");

ExportToExcel method

To set the ExportToExcel method, add the following code to the Click event of the Export button:

To write code in Visual Basic

Visual Basic
Copy Code
Me.C1TrueDBGrid1.ExportToExcel("c:\temp\composers.xls")

To write code in C#

C#
Copy Code
this.c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
Note: C1TrueDBGrid's export feature uses Reports for WinForms' components internally, and you may need to reference Reports for WinForms' assemblies (C1.Win.C1Report and C1.C1Report) if you are receiving an error related to the assembly.

What You've Accomplished

Clicking the Export button creates an Excel file in the temp directory indicated in the code above: