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).
FileName - full path of the
.xlsx file to create (overwritten if it already
exists).MemoCharLimit - affects Memo/CLOB
columns only: 0 (the default) exports the full text, a
positive value truncates to that many characters (still capped by
Excel’s own 32767-character-per-cell limit), and -1
excludes Memo/CLOB columns from the export entirely.SelectedRowsOnly - when
True, exports only the rows currently selected in the grid.
Falls back to exporting every record if the grid is not set up for
multi-selection (dgMultiSelect not in Options)
or no row is currently selected.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.
Each field is written as its native Excel type rather than as formatted text, so the result sorts and filters correctly in Excel:
Integer, Float,
Currency, BCD, FmtBCD, and
related types) -> Excel numbers.Column widths in the output are proportional to each column’s own
on-screen Width, converted to Excel’s character-based width
unit.
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.
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.