HotXLS Docs

Direct reader and writer API

Enterprise edition: High-volume streaming (lxDirectRead, lxDirectWrite and lxDirectTypes) ships only with HotXLS Enterprise (and Enterprise DCU), in the HotXLSEnterprise runtime package for RAD Studio and HotXLSLazEnterprise.lpk for Lazarus; the trial build includes it under the usual trial limits

TXLSDirectReader and TXLSDirectWriter process XLSX packages without holding a complete worksheet grid in memory, so API calls that describe a sheet must be made before or during the corresponding streaming phase

Writer lifecycle and cell values

TXLSDirectWriter.BeginFile or BeginStream starts a package, sheet methods define one worksheet at a time, and Finish commits the final package

Scalar cellsWriteString, WriteRichString, WriteNumber, WriteBoolean, WriteDateTime, and WriteError
Formula cellsWriteFormula, WriteFormulaNumber, WriteFormulaString, WriteFormulaBoolean, WriteFormulaDateTime, and WriteFormulaError accept caller-supplied cached results
Shared stringsUseSharedStrings enables package-level string deduplication
StatisticsCellCount reports the number of emitted cells
PanesFreezePanes(ColSplit, RowSplit) writes a frozen split at the given one-based column and row

Rows and columns are one-based in the public writer surface and must be supplied in forward worksheet order

TXLSDirectWriter.OnProgress (type TXLSDirectWriterProgress) reports per-interval streaming counts while rows are written — RowsWritten, CellsWritten, and BytesWritten — and setting its Cancel flag asks the writer to stop at the next row boundary

TXLSDirectWriter.DeclareDimension takes the column and row count before AddSheet. The dimension hint is then written up front instead of being learned from the rows, so an export that does not track column widths streams straight into the package and no staged copy of the worksheet exists at all; the declaration is the caller’s promise, and a cell beyond it is still written but not reflected in the hint. Zero clears it. With TrackColumnWidths the sheet is still staged for its width block, and the declared dimension is emitted from the flush in the same place, so both paths produce the same worksheet part

TXLSDirectWriter.TrackColumnWidths stages the worksheet part so the writer can emit its dimension hint and a <cols> block of tracked widths before the rows. SheetStageSpoolBudget bounds how much of that stage stays in memory: past it the stage rolls to a temporary file and reads back from there, so a very large export keeps a small resident size instead of holding its whole XML. The default of zero stages everything in memory, exactly as before, and SheetStageSpoolFileBytes and SheetStagePeakMemoryBytes report what the stage actually used

Worksheet patch lifecycle

BeginPatch replaces one worksheet or inserts a new worksheet while preserving untouched package parts. Failed initialization releases the source archive and source stream immediately, including a missing worksheet, missing required package part, invalid archive or destination creation failure. Source files and caller-owned temporary registrations remain the caller's responsibility; released handles allow those sources to be removed or released

Close and destruction release source handles even when there is no active destination or patch finalization raises an exception. An unsuccessful destination replacement retains its staged output for inspection, and the writer can start a subsequent patch or ordinary file operation after initialization failure

Reusable styles

AddCellStyle registers an immutable package-level style handle and CloneCellStyle derives a new handle without retaining worksheet rows

Defined names and hyperlinks

AddDefinedName, AddLocalDefinedName, AddDefinedRange, and AddLocalDefinedRange add workbook or sheet-local names before package finalization

AddHyperlink, AddHyperlinkRange, AddInternalHyperlink, and AddInternalHyperlinkRange emit external relationships or internal sheet locations for one cell or a range

Data validation

AddDataValidation and AddDataValidationSqRef expose the complete rule surface, while AddListValidation, AddWholeNumberValidation, AddDecimalValidation, AddDateValidation, AddTimeValidation, AddTextLengthValidation, and AddCustomValidation provide typed helpers

Conditional formatting

AddConditionalFormat, AddConditionalFormatExpression, AddConditionalFormatContainsText, AddConditionalFormatNotContainsText, AddConditionalFormatBeginsWith, AddConditionalFormatEndsWith, AddConditionalFormatTop10, AddConditionalFormatAboveAverage, AddConditionalFormatDuplicateValues, AddConditionalFormatUniqueValues, AddConditionalFormatContainsBlanks, AddConditionalFormatNotContainsBlanks, AddConditionalFormatContainsErrors, and AddConditionalFormatNotContainsErrors add scalar rules

AddConditionalFormatDataBar, AddConditionalFormatColorScale2, AddConditionalFormatColorScale3, and AddConditionalFormatIconSet add visual rules; ClearConditionalFormats removes pending rules for the current sheet

AutoFilter and tables

AddAutoFilterValue, AddAutoFilterDateGroup, and AddAutoFilterSortCondition configure the worksheet filter

AddTable creates a table part, and AddTableFilterValue, AddTableFilterDateGroup, and AddTableSortCondition configure its filter and sort state

Protection and page breaks

ProtectSheet, UnprotectSheet, AddProtectedRange, and ClearProtectedRanges configure worksheet protection; ProtectWorkbook and UnprotectWorkbook configure workbook structure and window locks

AddHorizontalPageBreak and AddVerticalPageBreak emit manual page breaks for the current worksheet

Reader string escapes

Version 2.384.536 decodes SpreadsheetML _xHHHH_ escapes once per complete string text leaf in shared strings, inline strings, rich-text and phonetic runs, and cached formula string values

A token split across parser callbacks or CDATA inside one text leaf is decoded after that leaf is complete; separate rich-text runs remain separate decoding domains, and an escaped underscore preserves literal escape-looking text without a second decode during shared-string lookup

The same decoded values are retained by memory-backed and disk-backed shared strings, column projection and the XLSX row-cursor path; formula expressions, numeric values and metadata do not acquire string-escape decoding

This reader capability belongs to Enterprise and follows the existing shared-string memory limit, rich-text ownership and formula-state contracts

Direct reader storage diagnostics

TXLSDirectReader.SharedStringMemoryLimit bounds decoded shared-string memory, SharedStringsOnDisk reports migration to temporary indexed storage, SharedStringCount reports the loaded entry count, and ParallelDiag exposes bounded parallel-parser diagnostics

Reader projection and formula state

FirstRow, LastRow, IncludeColumn, and ClearColumnProjection push row and one-based column selection into the worksheet parser before value, formula, or rich-text allocation

IncludeFormulaText defaults to true; disabling it keeps cached values, coordinates, styles, and HasFormula while FormulaTextAvailable becomes false and Formula remains empty

Row cursor

TXLSRowCursor.Open accepts XLS, XLSX, XLSM, ODS, CSV, and TSV files or streams; ZIP auto-detection distinguishes ODS packages from Open XML workbooks before a sheet is opened

SelectSheet and SelectSheetByName choose a worksheet; SheetCount, SheetNames, SheetIndex, RowIndex, and Eof expose traversal state, while SharedStringMemoryLimit applies the same bounded shared-string policy as the direct reader

FirstRow, LastRow, IncludeColumn, and ClearColumnProjection use the same one-based filters across all cursor formats; pass options cannot change between FindFirst and EOF but become mutable again after EOF, sheet selection, or close

Each TXLSRowCursorCell reports HasFormula independently from FormulaTextAvailable; classic XLS exposes formula presence and cached results without claiming unavailable token text, while IncludeFormulaText can suppress XLSX and ODS formula text before accumulation

ODS traversal holds one physical row template, clips repeated row blocks to the requested interval, jumps directly between selected columns inside repeated spans, advances across covered cells without returning them as values, and reports invalid or grid-limited repeat counts through OnSkippedRecord

State distinguishes xrcsClosed, xrcsBeforeFirst, xrcsActive, xrcsEof, xrcsCancelled, and xrcsFaulted; Cancel is idempotent, invalidates the current row, and releases the active worksheet stream while retaining the source so an explicit sheet selection can start a new pass

The stream overload defaults to xsoBorrowed, restores the caller's initial position on close, and accepts xsoOwned to transfer ownership after a successful open; failed opens never consume caller ownership

CurrentRowView borrows the current row array without copying it and checks a generation before every access; advancing, selecting, cancelling, closing, or destroying the cursor invalidates the view and raises EXLSRowCursorViewInvalidated on later access

PeakRowBufferedBytes is a monotonic estimate since the most recent Open of the cell records, managed payloads, rich text, and format-backend data retained for one logical row; it is intended for bounded-memory regression diagnostics rather than exact heap accounting

SheetPassesStarted counts successful worksheet backend starts; inspecting sheet names or skipping a sheet through the callback facade does not open the worksheet part

Forward callback adapter

TXLSForwardReader delegates XLS, XLSX, ODS, CSV, and TSV decoding to TXLSRowCursor, converts each current-row cell into an OnCell callback, and preserves the same row bounds, column projection, formula state, rich text, password, skipped-record, stream-position, and bounded-buffer contracts

PeakRowBufferedBytes and SheetPassesStarted expose the shared cursor diagnostics on the callback surface, while classic XLS additionally retains ClassicBytesRead and ClassicPeakBufferedBytes

Reader events and record types

The reader and row cursor expose optional callbacks and plain records, all declared in lxDirectRead. Every callback follows the same shape: the record describes one streamed item, and setting Abort stops the scan (sheet events additionally accept SkipSheet)

CellsOnCell (type TXLSDirectCellEvent) delivers a TXLSDirectCell per cell whose Kind (TXLSDirectCellKind: xdkEmpty, xdkNumber, xdkString, xdkBoolean, xdkDate, xdkError) selects the populated value field; rich text travels as a TXLSDirectRichText holding TXLSDirectRichTextRun entries in a TXLSDirectRichTextRuns dynamic array, each run with a TXLSDirectRichColor (kind TXLSDirectRichColorKind), TXLSDirectRichUnderline, and TXLSDirectRichVertAlign, plus optional TXLSDirectPhoneticProperties and TXLSDirectPhoneticRun data in a TXLSDirectPhoneticRuns array
Sheet framingOnSheet (TXLSDirectSheetEvent) can skip a whole worksheet before its cells are parsed; OnSkippedRecord (TXLSDirectSkippedEvent) reports malformed or truncated content with the record id and reason
Sheet layoutOnDimension (type TXLSDirectDimensionEvent), OnSheetFormat (TXLSDirectSheetFormatEvent), OnColumn (TXLSDirectColumnEvent), OnRow (TXLSDirectRowEvent), OnMerge (TXLSDirectMergeEvent), and OnPane (TXLSDirectPaneEvent) deliver TXLSDirectDimension, TXLSDirectSheetFormat, TXLSDirectColumn, TXLSDirectRow, TXLSDirectMerge, and TXLSDirectPane records; pane state uses TXLSDirectPaneState (xdpsSplit, xdpsFrozen, xdpsFrozenSplit, xdpsUnknown)
Cursor stateTXLSRowCursor.State is a TXLSRowCursorState (xrcsClosed, xrcsBeforeFirst, xrcsActive, xrcsEof, xrcsCancelled, xrcsFaulted); the stream overload of Open takes a TXLSStreamOwnership (xsoBorrowed default, xsoOwned to transfer ownership), and CurrentRowView returns an IXLSRowCursorView borrowed view whose Valid property guards access and whose ValueByCol reads one cell of the borrowed row without copying; the view invalidates when the cursor advances

Writer parameter and style types

The writer's typed helpers (lxDirectWrite) accept records and enums so calls stay allocation-free: WriteRichString takes a TXLSDirectRichText; AddCellStyle builds a package-level style from a TXLSDirectCellStyle whose alignment (TXLSDirectHorizontalAlignment, TXLSDirectVerticalAlignment), underline (TXLSDirectUnderline), fill pattern (TXLSDirectFillPattern), and border sides (TXLSDirectStyleBorder with TXLSDirectBorderSide) mirror the OOXML style model. Conditional formats pass a TXLSDirectConditionalFormat with TXLSDirectCfKind / TXLSDirectCfOperator / TXLSDirectCfValue / TXLSDirectCfValueKind and TXLSDirectIconSetType, data validation a TXLSDirectDataValidation, tables a TXLSDirectTable, hyperlinks a TXLSDirectHyperlink, defined names a TXLSDirectDefinedName, differential styles a TXLSDirectDxfStyle, comments a TXLSDirectComment, images a TXLSDirectImage with TXLSDirectImageFormat, charts a TXLSDirectChart with TXLSDirectChartSeries and TXLSDirectChartType, merges a TXLSDirectMergeRange, protected ranges a TXLSDirectProtectedRange, sheet protection a TXLSDirectSheetProtectionOptions set of TXLSDirectSheetProtectionOption, auto-filter sort state a TXLSDirectSortState whose Conditions field holds TXLSDirectSortCondition records (range, direction, sort-by, custom list) in a TXLSDirectSortConditions array, column options a TXLSDirectColumnOption, and page geometry a TXLSDirectPageMargins record. A TXLSDirectTable carries its per-column filter state in TXLSDirectFilterColumn records (TXLSDirectFilterColumns) — values, blanks, custom and dynamic filters, top-10 settings — whose date buckets are TXLSDirectDateGroup records (year through second plus a grouping name) in a TXLSDirectDateGroups array; the same records back AddAutoFilterDateGroup and AddTableFilterDateGroup

TXLSDirectNeedRow = procedure(Sender: TObject; RowIndex: Integer;
  var Eof: Boolean) of object;

function XLSDirectColName(Col: Integer): WideString;
function XLSDirectParseRef(const Ref: WideString;
  out Col, Row: Integer): Boolean;
function XLSDirectPasswordHash(const Password: WideString): WideString;
      

OnNeedRow pulls rows from the application: the supplier writes the row's cells straight through the writer and leaves Eof = False, or declares exhaustion with Eof = True to stop the loop. The helpers convert between coordinates and protection primitives: XLSDirectColName renders a zero-based column as its A1 letters, XLSDirectParseRef parses an A1 cell reference, and XLSDirectPasswordHash computes the legacy password hash the sheet-protection records store

See also