Custom Export
- 3 minutes to read
Tip
In v17.2 and higher, we recommend that you use the client API, built-in toolbar, and context menu commands to export ASPxGridView data.
The ASPxGridViewExporter component allows you to export ASPxGridView data to a file or stream in PDF, RTF, CSV, DOCX, XLS, and XLSX formats. You can also use standard toolbar commands, and client-side and server-side API to access the built-in export mechanism.
Assign ASPxGridView’s ID to the ASPxGridViewExporter.GridViewID property and select the export method. For example, use the ASPxGridExporterBase.WriteXlsToResponse method to export data to a file in XLS format. Refer to the following topic to review a list of available export methods: Member Table: Custom Export.
Use the ASPxGridViewDetailSettings.ExportMode property to specify which detail rows are exported. For example, set this property to Expanded to export only master rows and expanded detail rows.
The ASPxGridViewExporter.Styles property allows you to customize the exported grid’s element appearance.
Important
- The ASPxGridViewExporter cannot export hidden data columns or template content. The ASPxGridViewExporter identifies grids within GridViewTemplates.DetailRow templates, and allows users to export both master and detail data. Note that templated elements are exported with their default display views. For instance, if you export a grid with templated cells, they are displayed as default labels with text.
- Add the ASPxGridViewExporter to the page’s controls and recreate it on every round-trip to the server if it’s created dynamically.
Excel Data-Aware Export
The resulting Excel document maintains the following grid data when exporting data in both XLS and XLSX formats:
- Data grouping - allows users to collapse/expand groups in a worksheet.
- Data sorting and filtering - allows users to display relevant data in a specific order.
- Totals and group summaries - allow users to modify/change formulas.
- Format conditions - allow users to modify/change conditional formatting rules.
- Data validation for combo-box columns.
- Fixed columns.
Export Limitations
- When exporting data to Excel formats, the ASPxGridViewExporter.Landscape and ASPxGridViewExporter.PaperKind properties are not in effect.
- When exporting data to Excel formats, rich text formatting is ignored in ASPxGridViewExporter.ReportHeader and ASPxGridViewExporter.ReportFooter property values.
- The ASPxGridView control does not interpret HTML tags in data cells. Use the RenderBrick (WYSIWYG export mode) and XlsxExportOptionsEx.CustomizeCell (DataAware export mode) events to customize exported documents that contain HTML tags.
Data Aware Mode Limitations
- The ASPxGridViewExporter.Styles property has no effect. Use either the GridViewColumn.ExportCellStyle property at the column level or the XlsExportOptionsEx.CustomizeCell / XlsxExportOptionsEx.CustomizeCell event instead.
- The ASPxGridViewExporter.ReportHeader and ASPxGridViewExporter.ReportFooter properties are not in effect.
- The ASPxGridViewExporter.RenderBrick event does not fire. You can use the XlsExportOptionsEx.CustomizeCell or XlsxExportOptionsEx.CustomizeCell event instead.
- The master-detail grid export feature is not supported.
You can avoid the specified limitations if you use WYSIWYG (What You See Is What You Get) export mode. However, note that table formatting (for example, grouping) is lost in this mode.
gridExport.WriteXlsxToResponse(new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });