This example shows how to export the grid's data to a file in XLSX format and customize the output. The example uses the GridControl.ExportToXlsx method, which takes a parameter (XlsxExportOptionsEx) that regulates export settings and behavior, and implements events that allow you to add a header and footer to the export output, customize cells, add rows, etc.
-
The XlsxExportOptionsEx.CustomizeSheetHeader event is handled to add a header with custom information to the generated Microsoft Excel document. The
e.ExportContext.AddRow
,e.ExportContext.InsertImage
, ande.ExportContext.MergeCells
methods are used to add rows with the company name and contact information, insert the company logo, and merge certain cells. Cell formatting is specified using objects of theXlFormattingObject
class. -
The XlsxExportOptionsEx.CustomizeCell event is handled to replace values in the Discontinued column with special symbols. The
e.ColumnFieldName
event parameter identifies the column. Thee.Value
parameter is used to substitute certain cell values. Thee.Handled
parameter is set to true to apply the changes made. -
The XlsxExportOptionsEx.AfterAddRow event is handled to merge cells in rows that correspond to the grid's group rows. The
e.ExportContext.MergeCells
method is used to merge cells. Thee.DataSourceRowIndex
event parameter returns negative values for group rows. Thee.DocumentRow
parameter specifies the current row in the export output. -
The XlsxExportOptionsEx.CustomizeSheetFooter event is handled to add a footer to the document. The event handler uses the
e.ExportContext.AddRow
method to add two rows to the output document. Format settings are specified using objects of theXlFormattingObject
class. -
The XlsxExportOptionsEx.CustomizeSheetSettings event is handled to specify export settings. The
e.ExportContext.SetFixedHeader
method is used to anchor the output document's header to the top, and to set the fixed header height. Thee.ExportContext.AddAutoFilter
method is used to add the AutoFilter button to cells that correspond to grid column headers.
(you will be redirected to DevExpress.com to submit your response)