# Export to Excel/PDF

## Content

## Export to Excel

`FlexGrid` can export data to <span data-testid="definition-highlighter" class="_5pioz8co _189e1dm9 _1il9buyh _19lc184f _d0altlke" style="border-image: linear-gradient(90deg, rgb(0, 101, 255), rgb(191, 99, 243), rgb(245, 230, 168)) 0 0 100% / 1 / 0 stretch; border-width: 1.6px; border-bottom-style: solid; --_11qfq0e: solid;">CSV</span>, PDF, <span data-testid="definition-highlighter" class="_5pioz8co _189e1dm9 _1il9buyh _19lc184f _d0altlke" style="border-image: linear-gradient(90deg, rgb(0, 101, 255), rgb(191, 99, 243), rgb(245, 230, 168)) 0 0 100% / 1 / 0 stretch; border-width: 1.6px; border-bottom-style: solid; --_11qfq0e: solid;">XLSX</span>/<span data-testid="definition-highlighter" class="_5pioz8co _189e1dm9 _1il9buyh _19lc184f _d0altlke" style="border-image: linear-gradient(90deg, rgb(0, 101, 255), rgb(191, 99, 243), rgb(245, 230, 168)) 0 0 100% / 1 / 0 stretch; border-width: 1.6px; border-bottom-style: solid; --_11qfq0e: solid;">XLSM</span>, 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.

|
|
|

| @cols=1:**Member** | @cols=1:**Description** |
| ------ | ----------- |
| @cols=1:@rows=1:`.``<span data-highlighted="true" data-vc="highlighted-text" style="box-sizing: border-box;">xlsx</span>` `.``<span data-highlighted="true" data-vc="highlighted-text" style="box-sizing: border-box;">xlsm</span>` | @cols=1:@rows=1:Exports to an Excel Workbook |
| @cols=1:@rows=1:`.``<span data-highlighted="true" data-vc="highlighted-text" style="box-sizing: border-box;">csv</span>` | @cols=1:@rows=1:Exports to a Comma Separated Values file |
| @cols=1:@rows=1:`.htm` `.html` | @cols=1:@rows=1:Exports to a HTML file |
| @cols=1:@rows=1:`.pdf` | @cols=1:@rows=1: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.

|
|
|

| @cols=1:**Option** | @cols=1:**Description** |
| ------ | ----------- |
| @cols=1:@rows=1:VisibleOnly | @cols=1:@rows=1:Renders only visible row(s) and/or column(s) |
| @cols=1:@rows=1:RenderFrozen | @cols=1:@rows=1:Renders the frozen row(s) and/or column(s) |
| @cols=1:@rows=1:SelectedOnly | @cols=1:@rows=1:Renders only the selected row(s) and/or column(s) |
| @cols=1:@rows=1:ExludeRange | @cols=1:@rows=1:Excludes explicitly specified ranges |
| @cols=1:@rows=1:ExcludeEmpty (Row only) | @cols=1:@rows=1:Excludes empty rows |
| @cols=1:@rows=1:RenderGroups (Row only) | @cols=1:@rows=1: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.

|
|
|

| @cols=1:**Option** | @cols=1:**Description** |
| ------ | ----------- |
| @cols=1:@rows=1:None | @cols=1:@rows=1:No header cells are displayed in the output file. |
| @cols=1:@rows=1:All | @cols=1:@rows=1:Both column and row header cells are displayed in the output file. |
| @cols=1:@rows=1:Column | @cols=1:@rows=1:Only column header cells are displayed in the output file. |
| @cols=1:@rows=1:Row | @cols=1:@rows=1: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.

|
|
|

| @cols=1:**Option** | @cols=1:**Description** |
| ------ | ----------- |
| @cols=1:@rows=1:RenderMergedRanges | @cols=1:@rows=1:Render merged ranges in the output |
| @cols=1:@rows=1:RenderFormattedValues | @cols=1:@rows=1:Render cell values as formatted in the output |
| @cols=1:@rows=1:RenderImages | @cols=1:@rows=1: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".

```auto
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 { }
  }
```

>type=info
> * Use `SaveAsync` to export `FlexGrid` data to Excel, PDF, <span data-highlighted="true" data-vc="highlighted-text">CSV</span>, and HTML formats.
> * File selection must be implemented using platform-specific APIs such as `FileSavePicker`.