True DBGrid for WinForms | ComponentOne
In This Topic
    Export to Excel
    In This Topic

    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:

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

    Clicking the Export button creates an Excel file as given below:

    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:

    C#
    Copy Code
    c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
    
    C#
    Copy Code
    this.c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
    
    Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

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