Back to Devexpress

XlsxExportOptionsEx.BeforeExportTable Event

corelibraries-devexpress-dot-xtraprinting-dot-xlsxexportoptionsex-0c5d9b71.md

latest3.8 KB
Original Source

XlsxExportOptionsEx.BeforeExportTable Event

Allows you to customize a native Excel table’s settings before export. This event is in effect when the XlsxExportOptionsEx.LayoutMode property is set to Table.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public event BeforeExportTable BeforeExportTable
vb
Public Event BeforeExportTable As BeforeExportTable

Example

The following example shows how to change the style of the native Excel table to which data is exported from a grid control.

csharp
using DevExpress.Export.Xl;
using DevExpress.XtraPrinting;

string path = "gridNative.xlsx";
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
options.LayoutMode = DevExpress.Export.LayoutMode.Table;
options.BeforeExportTable += ea => {
    ea.Table.Style.Name = XlBuiltInTableStyleId.Medium1;
};
gridControl1.ExportToXlsx(path, options);
vb
Imports DevExpress.Export.Xl
Imports DevExpress.XtraPrinting

Dim path As String = "gridNative.xlsx"
Dim options As XlsxExportOptionsEx = New XlsxExportOptionsEx()
options.LayoutMode = DevExpress.Export.LayoutMode.Table
AddHandler options.BeforeExportTable,
    Sub(ea)
        ea.Table.Style.Name = XlBuiltInTableStyleId.Medium1
    End Sub
gridControl1.ExportToXlsx(path, options)

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BeforeExportTable event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-export-data-to-native-excel-table/CS/WpfApplication80/MainWindow.xaml.cs#L25

csharp
};
options.BeforeExportTable += options_BeforeExportTable;
view.ExportToXlsx("Document.xlsx", options);

wpf-data-grid-export-data-to-native-excel-table/VB/WpfApplication80/MainWindow.xaml.vb#L25

vb
Dim options As XlsxExportOptionsEx = New XlsxExportOptionsEx() With {.UnboundExpressionExportMode = UnboundExpressionExportMode.AsFormula, .LayoutMode = LayoutMode.Table}
AddHandler options.BeforeExportTable, AddressOf options_BeforeExportTable
Me.view.ExportToXlsx("Document.xlsx", options)

See Also

LayoutMode

XlsxExportOptionsEx Class

XlsxExportOptionsEx Members

DevExpress.XtraPrinting Namespace