Skip to main content

Data-Aware Export

  • 4 minutes to read

Run Demo: Data-Aware Export

The data-aware export is the default export mode for the XLS, XLSX, and CSV formats. This mode allows you to transfer data shaping operations (filters, groups, conditional formatting, etc.) into a document. The data-aware mode provides improved performance and memory usage compared to WYSIWYG mode.

Note

The CardView does not support the data-aware export.

Supported Data Shaping Features

The data-aware export mode retains the following grid data shaping features in the exported documents:

Export Data

The following code sample exports the GridControl to the Xls file:

void Button_Click_Export(object sender, RoutedEventArgs e) {
    view.ExportToXls(@"c:\Example\grid_export.xls");
}

The following methods export GridControl data in the data-aware mode:

Method Description
TableView.ExportToCsv, TreeListView.ExportToCsv Exports a grid to the specified stream in CSV format.
TableView.ExportToXls, TreeListView.ExportToXls Exports a grid to the specified file path in XLS format.
TableView.ExportToXlsx, TreeListView.ExportToXlsx Exports a grid to the specified stream in XLSX format.

The BaseColumn.AllowPrinting property specifies whether to export the column.

Customize Appearance

Note

The exported GridControl ignores the DataViewBase.CellTemplate and regular Template/Style properties. Refer to the Format Cell Values topic for information on what properties affect the data-aware export mode.

The following code sample changes the Birthday column’s width and the background color of odd rows in the exported document:

void Button_Click_Export(object sender, RoutedEventArgs e) {
    XlsExportOptionsEx options = new XlsExportOptionsEx();
    options.CustomizeCell += Options_CustomizeCell;
    options.CustomizeDocumentColumn += Options_CustomizeDocumentColumn;
    view.ExportToXls(@"c:\Example\grid_export.xls", options);
}
void Options_CustomizeCell(CustomizeCellEventArgs e) {
    if (e.DocumentRow % 2 != 0)
        e.Formatting.BackColor = System.Drawing.Color.PeachPuff;
    e.Handled = true;
}
void Options_CustomizeDocumentColumn(CustomizeDocumentColumnEventArgs e) {
    if (e.ColumnFieldName == "Birthday")
        e.DocumentColumn.WidthInPixels = 300;
}

To customize the resulting document in the data-aware export mode, use members of the XlsxExportOptionsEx, XlsExportOptionsEx, or CsvExportOptionsEx classes.

View Example: Add Page Headers and Footers to Exported Data

Event Description
XlsxExportOptionsEx.CustomizeCell, XlsExportOptionsEx.CustomizeCell, CsvExportOptionsEx.CustomizeCell Allows you to customize a cell in the output document.
XlsxExportOptionsEx.CustomizeDocumentColumn, XlsExportOptionsEx.CustomizeDocumentColumn Allows you to customize an individual column in the output document (for example, change its width, formatting, collapse the group containing the column or hide the column).
XlsxExportOptionsEx.CustomizeSheetFooter, XlsExportOptionsEx.CustomizeSheetFooter Allows you to add a footer to the output document.
XlsxExportOptionsEx.CustomizeSheetHeader, XlsExportOptionsEx.CustomizeSheetHeader Allows you to add a header to the output document.
XlsxExportOptionsEx.CustomizeSheetSettings, XlsExportOptionsEx.CustomizeSheetSettings Allows you to customize the output document’s settings.

Limitations

Refer to the following help topic for more information: Excel Export Specifications and Limits.

See Also