Skip to main content

Export to Tabular Formats (CSV, XLS, XLSX)

  • 6 minutes to read

The Export to tabular data formats (CSV, XLS, XLSX) feature uses the data engine the ExportType enumeration specifies. The default engine uses the Excel Export Library to perform a Data-Aware export with improved performance and reduced memory usage. The resultant file is optimized for subsequent analysis in Microsoft Excel.

Data-Aware Export

mvc-pivotgrid-export-xlsx-data-aware

The following features are retained in XLS and XLSX documents:

  • Data Grouping - you can collapse/expand groups within a worksheet.
  • Fixed Headers - column and row areas stay in sight.
  • Cells Formatting - retains the number format.
  • Display Text/Value export - you can select whether to export display text or values.

Methods

The following table lists the methods that perform data-aware export:

Method

Parameter

PivotGridExtension.ExportToCsv

Use the CsvExportOptionsEx instance instead of the CsvExportOptions object specified in the method signature.

The CsvExportOptionsEx.ExportType property should be set to the ExportType.DataAware value (default).

PivotGridExtension.ExportToXls

Use the PivotXlsExportOptions instance instead of the XlsExportOptions object specified in the method signature.

The PivotXlsExportOptions.ExportType (inherited XlsExportOptionsEx.ExportType) property should be set to the ExportType.DataAware value (default).

PivotGridExtension.ExportToXlsx

Use the PivotXlsxExportOptions instance instead of the XlsxExportOptions object specified in the method signature.

The PivotXlsxExportOptions.ExportType (inherited XlsxExportOptionsEx.ExportType) property should be set to the ExportType.DataAware value (default).

Options

The PivotXlsExportOptions and PivotXlsxExportOptions classes inherits properties from the XlsExportOptionsEx and XlsxExportOptionsEx classes, respectively. The data-aware export engine uses only a subset of available properties. The table below lists the properties which are in effect in the Data Aware mode.

Property

Description

PivotXlsExportOptionsBase.ExportColumnAreaHeaders, PivotXlsxExportOptionsBase.ExportColumnAreaHeaders

Gets or sets whether to include the column field headers in the exported document.

PivotXlsExportOptionsBase.ExportDataAreaHeaders, PivotXlsxExportOptionsBase.ExportDataAreaHeaders

Gets or sets whether to include the data field headers in the exported document.

PivotXlsExportOptionsBase.ExportFilterAreaHeaders, PivotXlsxExportOptionsBase.ExportFilterAreaHeaders

Gets or sets whether to include the filter field headers in the exported document.

PivotXlsExportOptionsBase.ExportRowAreaHeaders, PivotXlsxExportOptionsBase.ExportRowAreaHeaders

Gets or sets whether to include the row field headers in the exported document.

XlExportOptionsBase.SheetName

Gets or sets a name of the sheet in the created XLS file to which a document is exported.

XlsExportOptionsEx.AllowFixedColumns

XlsxExportOptionsEx.AllowFixedColumns

Gets or sets whether the row area in a Pivot Grid control becomes a frozen pane in the spreadsheet.

XlsExportOptionsEx.AllowFixedColumnHeaderPanel

XlsxExportOptionsEx.AllowFixedColumnHeaderPanel

Gets or sets whether the column area becomes a frozen pane in the spreadsheet.

XlsExportOptionsEx.AllowGrouping

XlsxExportOptionsEx.AllowGrouping

Gets or sets whether the data in the spreadsheet are grouped as they are displayed in the Pivot Grid control.

XlsExportOptionsEx.ShowPageTitle

XlsxExportOptionsEx.ShowPageTitle

Gets or sets whether each printed page of the exported document displays a title.

XlsExportOptionsEx.ExportType

XlsxExportOptionsEx.ExportType

Gets or sets the export mode. You can switch between WYSIWYG and data-aware export.

XlsExportOptionsEx.GroupState

XlsxExportOptionsEx.GroupState

Gets or sets whether groups are collapsed or expanded in the exported document.

XlExportOptionsBase.RawDataMode

Enables the mode that produces simple tabular data without graphic elements, style, and appearance settings.

XlExportOptionsBase.TextExportMode

Specifies whether data is exported as strings or values.

Runtime Customization

Handle the following events to customize exported pivot grid elements individually. Note that these events are in effect only in the Data Aware mode.

Event Description
PivotXlsExportOptions.CustomizeCell, PivotXlsxExportOptions.CustomizeCell Allows you to specify cell formatting in the exported spreadsheet..
XlsExportOptionsEx.AfterAddRow, XlsxExportOptionsEx.AfterAddRow, Fires after a row is added to the output document and allows you to merge cells, insert an image or add an extra row.
XlsExportOptionsEx.BeforeExportTable, XlsxExportOptionsEx.BeforeExportTable Allows you to customize a native Excel table’s settings before export.
XlsExportOptionsEx.CustomizeDocumentColumn, XlsxExportOptionsEx.CustomizeDocumentColumn Allows you to customize an individual column in the exported document - change its width, formatting, collapse the group containing the column or hide the column.
XlsExportOptionsEx.CustomizeSheetFooter, XlsxExportOptionsEx.CustomizeSheetFooter Allows you to add a footer to the output document.
XlsExportOptionsEx.CustomizeSheetHeader, XlsxExportOptionsEx.CustomizeSheetHeader Allows you to add a header to the output document.
XlsExportOptionsEx.CustomizeSheetSettings, XlsxExportOptionsEx.CustomizeSheetSettings Allows you to customize the output document’s settings.
XlsExportOptionsEx.DocumentColumnFiltering, XlsxExportOptionsEx.DocumentColumnFiltering Allows you to apply filters to the exported document’s columns.>
XlsExportOptionsEx.SkipFooterRow, XlsxExportOptionsEx.SkipFooterRow Allows you to hide certain summary footers (or certain multi-line summary footers’ lines) from the exported document.

WYSIWYG Export

The WYSIWYG export mode uses the XtraPrinting library engine. It reproduces control elements’ layout in XLS and XLSX formats, omitting data shaping characteristics available in the DataAware export mode.

mvc-pivotgrid-export-xlsx-wysiwyg

In CSV format, the WYSIWYG mode can export data area and filter area headers, and add empty columns. When a spreadsheet loads CSV data, it looks similar to the original Pivot Grid control.

WYSIWYG Mode Data Aware Mode
Export_CSV_WYSIWYG Export_CSV_DataAware

The following table lists the methods that perform the export in WYSIWYG mode:

Method

Parameter

PivotGridExtension.ExportToCsv

Use the CsvExportOptionsEx instance instead of the CsvExportOptions object specified in the method signature.

The CsvExportOptionsEx.ExportType property should be set to the ExportType.WYSIWYG value.

PivotGridExtension.ExportToXls

Use the PivotXlsExportOptions instance instead of the XlsExportOptions object specified in the method signature.

The PivotXlsExportOptions.ExportType (inherited XlsExportOptionsEx.ExportType) property should be set to the ExportType.WYSIWYG value.

PivotGridExtension.ExportToXlsx

Use the PivotXlsxExportOptions instance instead of the XlsxExportOptions object specified in the method signature.

The PivotXlsxExportOptions.ExportType (inherited XlsxExportOptionsEx.ExportType) property should be set to the ExportType.WYSIWYG value.

Options

The PivotXlsExportOptions and PivotXlsxExportOptions classes inherits properties from the XlsExportOptionsEx and XlsxExportOptionsEx classes, respectively. The WYSIWYG mode (the Printing Library export engine) uses only a subset of available properties. The table below lists the properties which are in effect in the WYSIWYG mode.

Property Description
XlExportOptionsBase.DocumentOptions Provides access to options to be embedded as the resulting XLS or XLSX file’s Document Properties.
XlExportOptionsBase.EncryptionOptions Provides access to the XLS and XLSX file encryption options.
XlsExportOptions.ExportMode, XlsxExportOptions.ExportMode, Specifies whether the source is exported as a single XLSX file or multiple files, and whether each page is exported as a separate worksheet.
XlsExportOptionsEx.ExportType, XlsExportOptionsEx.ExportType Gets or sets the export type - WYSIWYG or Data Aware.
XlExportOptionsBase.IgnoreErrors Specifies the document errors to be ignored in a resulting Excel file.
XlExportOptionsBase.RawDataMode Enables the mode that produces simple tabular data without graphic elements, style and appearance settings.
XlExportOptionsBase.RightToLeftDocument Gets or sets whether the layout of the resulting XLS document should be aligned to support locales using right-to-left fonts.
XlExportOptionsBase.SheetName Gets or sets a name of the sheet in the created XLS file to which a document is exported.
XlExportOptionsBase.ShowGridLines Gets or sets whether worksheet gridlines are visible in the resulting XLS file.
XlsExportOptions.Suppress256ColumnsWarning Gets or sets a value indicating whether to suppress the exception that raises when trying to export a document to an XLS file with more than 256 columns.
XlsExportOptions.Suppress65536RowsWarning Gets or sets a value indicating whether to suppress the exception that raises when trying to export a document to an XLS file with more than 65,536 rows.
XlExportOptionsBase.TextExportMode Gets or sets a value indicating whether the cells in the resulting XLS document should use the same formatting as the original document.