ExportToXLSX

Class: TEgDBGridEx

procedure ExportToXLSX(const FileName: string; MemoCharLimit: Integer = 0;
  SelectedRowsOnly: Boolean = False);

Exports the grid’s underlying data - not its on-screen appearance - to a .xlsx workbook, one row per record and one column per exported grid column, with no third-party dependency. Raises an exception if there is no active dataset, or if no column qualifies for export (see below).

Which columns are exported

A column is exported only if it is Visible, has a Field assigned (a Custom Cell column with no FieldName is skipped - see OnBeforeDrawCell), and its field is not a graphic/BLOB image. A checkbox column is not excluded on that account: a Boolean field is exported like any other, as a native Excel boolean - only its on-screen checkbox glyph, not its value, is grid-only appearance. A Memo/CLOB column is excluded when MemoCharLimit is -1 (see above). Exported columns follow the grid’s current visual left-to-right order, not their creation order, with each header taken from Title.Caption.

How field values are converted

Each field is written as its native Excel type rather than as formatted text, so the result sorts and filters correctly in Excel:

Column widths in the output are proportional to each column’s own on-screen Width, converted to Excel’s character-based width unit.

What is not exported

Cell-level appearance (colors, fonts, alignment, checkbox glyphs, images) and any text supplied only through OnBeforeDrawCell for a Custom Cell column - only field data is exported.

Progress reporting

OnExportProgress, when assigned, fires during the export to report progress as a percentage (0-100): once at the very start, at most once per whole-percent change as the dataset is traversed, and once at the end - see OnExportProgress’s own page for the exact firing rules, including how SelectedRowsOnly affects what the percentage actually measures.

See Also

(C) 2026 Easygate, Lda