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.MergeCellsmethods 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 theXlFormattingObjectclass. -
The XlsxExportOptionsEx.CustomizeCell event is handled to replace values in the Discontinued column with special symbols. The
e.ColumnFieldNameevent parameter identifies the column. Thee.Valueparameter is used to substitute certain cell values. Thee.Handledparameter 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.MergeCellsmethod is used to merge cells. Thee.DataSourceRowIndexevent parameter returns negative values for group rows. Thee.DocumentRowparameter 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.AddRowmethod to add two rows to the output document. Format settings are specified using objects of theXlFormattingObjectclass. -
The XlsxExportOptionsEx.CustomizeSheetSettings event is handled to specify export settings. The
e.ExportContext.SetFixedHeadermethod is used to anchor the output document's header to the top, and to set the fixed header height. Thee.ExportContext.AddAutoFiltermethod 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)