Skip to main content
A newer version of this page is available. .

How to: Export ASP.NET MVC Pivot Grid to PDF and XLSX Formats with Custom Settings

  • 2 minutes to read

This example demonstrates how to export the ASP.NET MVC Pivot Grid to PDF and XLSX formats, specify various export options and customize the exported cell’s content and appearance.

Note

The complete sample project How to Export ASP.NET MVC Pivot Grid to PDF and XLSX Formats with Custom Settings is available in the DevExpress Examples repository.

The following image shows the Pivot Grid control page when the example is run. Click the Export to XLSX (DataAware), Export to XLSX (WYSIWYG) or Export to PDF buttons to perform the export.

mvcxpivotgrid-export-original

Export to XLSX - Data Aware

Default export type is Data-Aware.

The PivotGridExtension.ExportToXlsx method exports the pivot grid to XLSX format. Export options are contained in the XlsxExportOptions object passed as the method’s parameter. The PivotXlsxExportOptions object is also accepted because it inherits the XlsxExportOptions class. Create the PivotXlsxExportOptions class instance, modify its properties and use it as the method’s parameter.

To customize a cell’s content and appearance, handle the PivotXlsxExportOptions.CustomizeCell event. The resultant file is shown below.

mvcxpivotgrid-export-to-xlsx-custom-data-aware

Export to XLSX - WYSIWYG

Call the PivotGridExtension.ExportToXlsx method with the XlsxExportOptionsEx parameter’s ExportType property set to ExportType.WYSIWYG to set the export type to WYSIWYG. The MVCxPivotGridExportSettings.CustomExportCell event is handled to customize each cell’s content and appearance. Note that the PivotXlsxExportOptions.CustomizeCell event does not occur for WYSIWYG export. The resultant file is shown below.

mvcxpivotgrid-export-to-xlsx-custom-wysiwyg

Export to PDF

The export to PDF is performed using the PivotGridExtension.ExportToPdf method with the PivotGridSettings instance passed as the method’s parameter. The MVCxPivotGridExportSettings.OptionsPrint property specifies page settings. The MVCxPivotGridExportSettings.CustomExportCell event is handled to customize each cell’s content and appearance. The resultant file is shown below.

mvcxpivotgrid-export-to-pdf-custom