[]
        
(Showing Draft Content)

Export to Excel/PDF

Export to Excel

FlexGrid can export data to CSV, PDF, XLSX/XLSM, and HTML using the C1.WinUI.Grid.Excel assembly. The export functionality is exposed through the asynchronous SaveAsync method.

Supported File Formats

These are the save file formats that this extension supports.

Member

Description

.xlsx .xlsm

Exports to an Excel Workbook

.csv

Exports to a Comma Separated Values file

.htm .html

Exports to a HTML file

.pdf

Exports to a PDF file

Options

Row and Column Options

This specifies options available for customizing the excel output when grid is exported. These are the row(s) and column(s) export options that this extension supports.

Option

Description

VisibleOnly

Renders only visible row(s) and/or column(s)

RenderFrozen

Renders the frozen row(s) and/or column(s)

SelectedOnly

Renders only the selected row(s) and/or column(s)

ExludeRange

Excludes explicitly specified ranges

ExcludeEmpty (Row only)

Excludes empty rows

RenderGroups (Row only)

Includes grouped rows

Header Options

This specifies constants that defines which header cells are displayed in the exported file. These are the row(s) and column(s) grid header visibility options that this extension supports.

Option

Description

None

No header cells are displayed in the output file.

All

Both column and row header cells are displayed in the output file.

Column

Only column header cells are displayed in the output file.

Row

Only row header cells are displayed in the output file.

Rendering Options

This specifies additional options available for rendering merged ranges, formatted values, and images.

Option

Description

RenderMergedRanges

Render merged ranges in the output

RenderFormattedValues

Render cell values as formatted in the output

RenderImages

Includes images; otherwise exports image URIs

 

Sample Usage

The following example shows how to use the SaveAsync method to export FlexGrid to Excel files. In this example, we used the Name property to name the FlexGrid control as "grid".

using C1.DataCollection;
using C1.WinUI.Core;
using C1.WinUI.Grid;
using GrapeCity.Documents.Excel;
private async void OnExportClick(object sender, RoutedEventArgs e)
  {
    var savePicker = new FileSavePicker();
    savePicker.DefaultFileExtension = ".xlsx";
    try
      {
        file = await savePicker.PickSaveFileAsync();
        await grid.SaveAsync(
          file.Path,
          "FlexGrid Sheet", //Sheet Name
          SaveFileFormat.Xlsm, //GrapeCity.Documents.Excel.SaveFileFormat: Represents the format in which the workbook is saved
          new GridRowColRanges("1-5", rows = GridRowColRangesOptions.VisibleOnly),
          new GridRowColRanges("1-5", columns = GridRowColRangesOptions.VisibleOnly),
          headers: GridHeadersVisibility.All,
          merged: checkMerged.IsChecked ?? false,
          formatted: checkFormatted.IsChecked ?? false,
          renderImages: checkRenderImages.IsChecked ?? false);
      }
      catch { }
  }
  • Use SaveAsync to export FlexGrid data to Excel, PDF, CSV, and HTML formats.

  • File selection must be implemented using platform-specific APIs such as FileSavePicker.