Skip to main content
Table of Contents

TTMSFNCDataGridExcelIO Class

Non-visual component that imports grid content from, and exports it to, Excel workbooks without requiring Excel to be installed.

API unit family: TMSFNCDataGridExcelIO Inherits from: TTMSFNCCustomComponent

Syntax

GeneratedPascalC++
TTMSFNCDataGridExcelIO = class(TTMSFNCCustomComponent)
class PASCALIMPLEMENTATION TTMSFNCDataGridExcelIO : public TTMSFNCCustomComponent

Remarks

Uses the built-in native XLS engine, which reads and writes the binary Excel 97-2003 format (BIFF8, .xls). Export always writes this format, whatever extension the file name has. Files with a .csv or .txt extension are not parsed; load delimited text with TTMSFNCCustomDataGrid.LoadFromCSVData instead.

Typical use: assign DataGrid (done automatically when the component is created on a form that already contains a grid), adjust Options and the start offsets, then call XLSExport or XLSImport. Per-cell export customisation is available through OnCellFormat, OnGetCellFormula, OnExportColumnFormat and OnDateTimeFormat.

By default DataGridStartRow and DataGridStartCol are 1, so grid row 0 and column 0 (usually the header row and a fixed column) are neither exported nor filled on import. Set them to 0 to include them.

Properties

Name Description
AutoResizeDataGrid When True (default), the grid's row and column count are adjusted on import to fit the worksheet's used range and any picture anchors.
DataGrid Grid whose content is imported or exported.
DataGridStartCol Zero-based grid column that corresponds to XlsStartCol. Default is 1.
DataGridStartRow Zero-based grid row that corresponds to XlsStartRow. Default is 1.
DateFormat Date format used on export to recognise dates in cell text and write them as Excel date values. Empty by default.
Options Import and export options: values and formats, appearance, formulas, images, sizes, overwrite handling and sheet settings.
Renderer Renderer whose cells are imported or exported.
SheetNames Worksheet names read by the last LoadSheetNames or XLSImport call, by zero-based index.
SheetNamesCount Number of worksheet names read by the last LoadSheetNames or XLSImport call; 0 before either has been called.
TimeFormat Time format used on export to recognise times in cell text and write them as Excel time values. Empty by default.
UseUnicode Reserved for backward compatibility; not used by the current import and export code. Text is always handled as Unicode.
Version Version of the underlying XLS engine. Read-only in practice; assigned values are ignored.
XlsStartCol One-based worksheet column that corresponds to DataGridStartCol. Default is 1.
XlsStartRow One-based worksheet row that corresponds to DataGridStartRow. Default is 1.
Zoom Zoom percentage used to scale imported row heights, column widths and font sizes when ZoomSaved is False. Default is 100.
ZoomSaved When True (default), imported sizes and fonts are scaled by the zoom level stored in the worksheet. When False, Zoom is used instead.

Methods

Name Description
LoadSheetNames Reads the worksheet names of a workbook into SheetNames without importing any data.
XLSExport Exports the grid to a worksheet of an XLS workbook.
XLSImport Imports the first worksheet of an XLS workbook into the grid.

Events

Name Description
OnCellFormat Occurs during export for each cell, to modify the Excel format (font, fill, alignment, borders, number format) written for it.
OnDateTimeFormat Occurs during export, for each cell converted to a typed value, to override the date and time formats used to recognise dates and times in its text.
OnExportColumnFormat Occurs during export for each cell, to decide whether it is written as literal text or converted to a number, date or time.
OnGetCellFormula Occurs during export for each cell, to supply an Excel formula to write instead of the cell value.
OnProgress Occurs during import and export to report progress.

Used by