FlexGrid for WPF | ComponentOne
Features / Export to Excel
In This Topic
    Export to Excel
    In This Topic

    FlexGrid allows you to export files to CSV, PDF, Xlsx/Xlsm, and HTML file formats with the help of the C1.WPF.Grid.Excel library. This library provides SaveAsync method in the Extensions class which can be used to export FlexGrid and save it to either the file system or a Stream. The SaveAsync method has two overloads depending on whether you need to save to a stream or the file system:

    Overloads Description
    SaveAsync(C1.WPF.Grid.FlexGrid,System.String,System.String,
    GrapeCity.Documents.Excel.SaveFileFormat,
    C1.WPF.Grid.GridRowColRanges,C1.WPF.Grid.GridRowColRanges,
    C1.WPF.Grid.GridHeadersVisibility,System.Boolean,System.Boolean,
    System.Boolean,System.Drawing.Printing.PrinterSettings)
    Saves the contents of the grid in a desired file format using GcExcel.
    SaveAsync(C1.WPF.Grid.FlexGrid,System.IO.Stream,System.String,
    GrapeCity.Documents.Excel.SaveFileFormat,
    C1.WPF.Grid.GridRowColRanges,C1.WPF.Grid.GridRowColRanges,
    C1.WPF.Grid.GridHeadersVisibility,System.Boolean,System.Boolean,
    System.Boolean,System.Drawing.Printing.PrinterSettings)
    Saves the contents of the grid in a stream in desired format using GcExcel.

    To export FlexGrid to any other format, you need to add the following dependencies to your application:

    The following example shows how to use the SaveAsync method to export FlexGrid to Excel files with XLSX/XSLM format. In this example, we used the Name property to name the FlexGrid control as "flex".

    C#
    Copy Code
    private void Save_Click(object sender, RoutedEventArgs e)
    {          
        flex.SaveAsync(@"..\..\..\..\FlexGridSheet_overload2.xlsx","flex Sheet",SaveFileFormat.Xlsx, new GridRowColRanges("1-3", GridRowColRangesOptions.VisibleOnly), new GridRowColRanges("1-3", GridRowColRangesOptions.VisibleOnly), GridHeadersVisibility.All, false,false, false, null);
    }