Exporting
- 3 minutes to read
The GridControl provides a fast and flexible way to export its data to a file or stream in various formats.
Overview
A View provides multiple methods to export its contents.
Method | Description |
---|---|
DataViewBase.ExportToHtml | Exports a grid to the specified file path in HTML format. |
DataViewBase.ExportToImage | Exports a grid to the specified file path in image format. |
DataViewBase.ExportToMht | Exports a grid to the specified file path in MHT format |
DataViewBase.ExportToPdf | Exports a grid to the specified file path in PDF format. |
DataViewBase.ExportToRtf | Exports a grid to the specified stream in RTF format. |
DataViewBase.ExportToText | Exports a grid to the specified stream in text format. |
DataViewBase.ExportToXps | Exports a grid to the specified file path in XPS format. |
TableView.ExportToCsv, TreeListView.ExportToCsv, CardView.ExportToCsv | Exports a grid to the specified stream in CSV format. |
TableView.ExportToXls, TreeListView.ExportToXls, CardView.ExportToXls | Exports a grid to the specified file path in XLS format. |
TableView.ExportToXlsx, TreeListView.ExportToXlsx, CardView.ExportToXlsx | Exports a grid to the specified stream in XLSX format. |
The Print Preview window allows you to customize the printed document, print or export it to a file in the required format. The image below illustrates the Print Preview window for a sample grid.
See the Printing Options section of the Printing topic to learn how to specify the View elements to be printed.
Export to XLS, XLSX, and CSV Formats
Data-aware Export
This is the default export mode, optimized for subsequent analysis of grid data within Microsoft Excel. Output documents retain various data shaping options that are applied within the grid. The data-aware export functionality provides improved performance and memory usage.
Note
Currently CardView does not support the data-aware export.
The GridControl supports the following features for all Excel export operations:
- Data Grouping - allows end-users to collapse/expand groups within a worksheet.
- Data Sorting and Filtering - allows end-users to display relevant data in the desired order.
- Totals and Group Summaries - allows end-users to modify/change formulas.
- Excel Style Conditional Formatting.
- Data Validation for lookup and combobox columns.
- Fixed Columns.
- Band Columns.
The data-aware export has the following limitations:
- Only master rows are shown when exporting master-detail data.
- Printing styles and templates are not supported.
- Custom summary export is not supported.
- Icon Sets that are used for conditional formatting are not supported.
Tip
You can handle the XlsExportOptionsEx.CustomizeCell / XlsxExportOptionsEx.CustomizeCell event to customize document cells.
WYSIWYG Export
In this export mode, resulting documents retain the layout of grid cells. Specific data shaping options are not retained, in comparison to the data-aware export.
Set the ExportSettings.DefaultExportType property to ExportType.WYSIWYG to enable the WYSIWYG export mode in an application.
The following code illustrates the WYSIWYG export to XLSX:
TableView.ExportToXlsx([Path], new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });
Tip
The GridControl uses the Printing-Exporting library to export the data. When you invoke the built-in ExportTo* methods or use the Printing Links, the GridControl produces similar output files. Use the second approach to customize page settings (refer to PrintableControlLink Members for a complete list of available options) or to export the data in a generic way.
Tip
You can declare custom Printing Styles and Templates to customize document elements.