Skip to main content

ExportGridToExcel(string,TcxGrid,Boolean,Boolean,Boolean,string,TObject) Method

Exports content of a data grid control to a file in Microsoft Excel® binary format (XLS).

Declaration

procedure ExportGridToExcel(const AFileName: string; AGrid: TcxGrid; AExpand: Boolean = True; ASaveAll: Boolean = True; AUseNativeFormat: Boolean = True; const AFileExt: string = 'xls'; AHandler: TObject = nil);

Parameters

Name Type Description
AFileName string

The full path to the resulting XLS file. You can omit the file name extension because it is automatically updated from the AFileExt parameter value.

AGrid TcxGrid

The source data grid control.

AExpand Boolean

Optional. If True, the procedure exports all rows, including the rows hidden within collapsed group rows and master rows. If False, the procedure exports only visible rows.

ASaveAll Boolean

Optional. If True, the procedure exports all or visible rows, depending on the AExpand parameter value. If False, the procedure exports only selected rows. In grid mode, the ASaveAll parameter value is ignored.

AUseNativeFormat Boolean

Optional. If True, the procedure attempts to convert display text of a grid item’s cells to their underlying data format (that is, Currency, Date, Time, Numeric, etc.) The table below lists supported in-place editors and the corresponding data formats. If False, the procedure exports display text as string values.

AFileExt string

Optional. Specifies the file name extension for the resulting XLS file. This parameter value always replaces the file name extension passed as a part of the AFileName parameter value.

AHandler TObject

Optional. Specifies a handler object that should implement the IcxExportBeforeSave and/or IcxExportProgress interfaces to allow you to perform specific actions before an export operation and track its progress. Refer to the following topic for detailed information on how to create and use handler objects: How to: Track Data Export Progress.

Remarks

If you pass True as the AUseNativeFormat parameter, the ExportGridToExcel procedure attempts to convert display text of a grid item’s cells to their underlying data format (Currency, Date, Time, Numeric, etc.) If you assign an in-place editor to a cell, the export procedure selects the data format according to the following table:

In-place Editor Data Format
TcxCurrencyEdit Currency
TcxMaskEdit or TcxCalcEdit Currency, if the assigned editor is bound to a dataset field whose values are formatted as currency values (TAggregateField.Currency, TBCDField.Currency, TFloatField.Currency, or TFMTBCDField.Currency). Otherwise, the data format is Number.
TcxDateEdit Date
TcxTimeEdit Time
TcxSpinEdit Number

If any other editor is assigned to a cell, the ExportGridToExcel procedure exports its display text regardless of the AUseNativeFormat parameter value. If it is impossible to convert display text to the target data type for any reason, the display text is exported as a string.

Note

The listed data formats are used for value conversion only. They do not correspond to cell number formats found in Microsoft Excel®. Populated cells have the General format.

Summary values use the same data type as cell values against which these summaries are calculated if the following conditions are met for the corresponding summary items:

  • An empty string is assigned to a summary item’s Format property.
  • An OnGetText event handler is not assigned to a summary item.

Example

Source Data Grid Example

The following code example exports grid content to a file in XLS format with expanded detail pages:

  ExportGridToExcel('Employees.xls', cxGrid1, True);

Exported Data in XLS Format

See Also