ASPxGridViewExporter Class
A component that allows you to export the ASPxGridView control’s data.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Remarks
Tip
We recommend that you use the built-in export functionality.
The ASPxGridViewExporter
component allows you to export ASPxGridView data to a file or stream in PDF, RTF, CSV, DOCX, XLS, and XLSX formats.
To export grid data, assign the grid control’s ID to the GridViewID property and call an export method.
<dx:ASPxGridView ID="grid" runat="server" DataSourceID="CustomerReportsDataSource" />
<dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" GridViewID="grid" />
Export Methods
The ASPxGridViewExporter
component implements the following export methods:
Format | Export to a Stream | Export to the Response in Binary Format |
---|---|---|
CSV | WriteCsv | WriteCsvToResponse |
DOCX | WriteDocx | WriteDocxToResponse |
WritePdf | WritePdfToResponse | |
RTF | WriteRtf | WriteRtfToResponse |
XLS | WriteXls | WriteXlsToResponse |
XLSX | WriteXlsx | WriteXlsxToResponse |
Excel Data-Aware Export
The ASPxGridViewExporter
component can export data in XLS and XLSX formats in data-aware mode. This mode maintains the following data shaping settings in the exported document:
- Data grouping.
- Data sorting and filtering.
- Totals and group summaries.
- Format conditions.
- Data validation for combo-box columns.
- Fixed columns.
You can export grid data in Excel data-aware mode in the following way:
using DevExpress.XtraPrinting;
using DevExpress.Export;
// ...
ASPxGridViewExporter1.WriteXlsxToResponse(new XlsxExportOptionsEx { ExportType = ExportType.DataAware });
Important Notes
- The exporter creates an exported document on a server. When you export a large amount of data to a server with limited memory, the OutOfMemoryException exception can appear.
- If you create a control dynamically, add the
ASPxGridViewExporter
component to a page and recreate the component on every round-trip to the server. - Don’t export the ASPxGridView‘s content during callbacks, because ASP.NET does not support sending binary content during a callback.
Limitations
- Hidden data columns are not exported.
- The exporter cannot export the content of templates (except for a detail ASPxGridView control placed in the DetailRow template).
- The ASPxGridView control does not interpret HTML tags in data cells. Use the RenderBrick (WYSIWYG export mode) and XlsExportOptionsEx.CustomizeCell/XlsxExportOptionsEx.CustomizeCell (DataAware export mode) events to customize exported documents that contain HTML tags.
- When exporting data in Excel formats, the Landscape and PaperKind properties are not in effect.
- When exporting data in Excel formats, rich text formatting is ignored in ASPxGridViewExporter.ReportHeader and ASPxGridViewExporter.ReportFooter property values.
Data-Aware Mode Limitations
- The master-detail grid export is not supported.
- The RenderBrick event does not fire. You can use the XlsExportOptionsEx.CustomizeCell or XlsxExportOptionsEx.CustomizeCell event instead.
- 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.
Use the default WYSIWYG export mode to avoid the specified limitations. Note that data shaping settings are lost in this mode.