Skip to content

Export

Starting with version 1.2, the DataGrid control can export data to XLSX (Microsoft Excel) format.

Note

Include the Eremex.DocumentProcessing library in your project to use the export feature.

Export to XLSX Format

The Excel export engine is data-aware, meaning it preserves the grid's data shaping options in the output XLSX document, including:

  • Row grouping
  • Value formatting
  • Data sorting

After data is exported, you can process and analyze it in Microsoft Excel or another worksheet processing application.

datagrid-export-result

Note

Cell formatting implemented using cell templates (GridColumn.CellTemplate) is not exported.

Use the following methods to export the control's data to XLSX format:

  • DataGridControl.ExportToXlsx(string fileName, XlsxExportOptions? options = null) — Exports data to a file.

  • DataGridControl.ExportToXlsx(Stream stream, XlsxExportOptions? options = null) — Exports data to a stream.

The optional options parameter (of type XlsxExportOptions) allows you to customize export settings. The XlsxExportOptions class exposes the following members:

  • ExportProgress event — Fires repeatedly during data export. The event's ExportProgressEventArgs.ProgressPercentage parameter indicates the progress as a percentage (0 to 100). You can use this event to display export progress to users in a customized way.
  • AllowFixedColumnHeaderPanel property (default is true) — Gets or sets whether the column header panel remains fixed at the top in the exported document.

  • ApplyFormattingToEntireColumn — Gets or sets whether cell formatting is applied to entire columns or individual cells in the output document.

  • AllowGrouping property (default is true) — Gets or sets whether group rows and the group hierarchy are exported. If AllowGrouping is false, data rows are only exported.

  • DocumentCulture — Gets or sets a custom CultureInfo object that determines formatting rules for numeric and date-time values in the output document.

    If the DocumentCulture property is not specified, the export engine uses the application's current culture.

  • ShowBands property (default is null) — Gets or sets whether the control's bands are included in the export.

    If ShowBands is null, the setting is specified by the control's DataGridControl.ShowBands property.

  • ShowColumnHeaders property (default is null) — Gets or sets whether the column header panel is included in the export.

    If ShowColumnHeaders is null, the setting is specified by the control's DataGridControl.ShowColumnHeaders property.

  • ShowHorizontalLines — Gets or sets whether horizontal lines between cells are visible in the output document.

  • ShowVerticalLines — Gets or sets whether vertical lines between cells are visible in the output document.

  • TextExportMode property — Gets or sets default export mode of cell values.

    Available options include:

    • TextExportMode.Value — Exports cell values. If cell values are formatted in the DataGrid control, the export engine attempts to apply matching formatting to the exported values in the output document.
    • TextExportMode.Text — Exports cell display text. If cell values are formatted in the DataGrid control, the formatted string representation is exported.

    You can use the GridColumn.TextExportMode property to override the XlsxExportOptions.TextExportMode setting for individual columns.

    Note

    The export engine only takes into account cell formatting applied using the GridColumn.EditorProperties property. For example:

    <mxdg:GridColumn Width="*" FieldName="Salary">
        <mxdg:GridColumn.EditorProperties>
            <mxe:TextEditorProperties DisplayFormatString="c"/>
        </mxdg:GridColumn.EditorProperties>
    </mxdg:GridColumn>
    

    Cell formatting applied using other approaches (for instance, with GridColumn.CellTemplate) is ignored during data export.