HotXLS Docs

Workbook Viewer Feature

Overview

In addition to file manipulation, Delphi desktop applications often need to visually display workbooks to users; HotXLS includes a visual control to render spreadsheets directly inside VCL and FMX forms

TXLSWorkbookViewer Control

The TXLSWorkbookViewer component provides scrolling, rectangular selection, editing, formula input, comments, hyperlinks, conditional formatting, and print preview without writing temporary files

Assign Workbook for classic XLS or XlsxWorkbook for XLSX, XLSB and ODS workbooks, or call LoadFromFile to let the control own the loaded workbook; LoadFromFile takes .xls, .xlsx, .xlsm, .xlsb, .xltx, .xltm and .ods files

Editing and Formula Input

Set Editable to True to enable F2, double-click, printable-key, Delete, and formula-bar editing; protected locked cells remain read only whilst explicitly unlocked cells remain editable

FormulaBarText returns the selected cell formula with its leading equals sign or its input value, and assigning the property applies a new formula or typed value and recalculates the dependent formulas

Undo and Redo use a bounded circular history controlled by UndoLimit; each cell edit, range clear, or text paste creates one transaction, and undo brings back sparse absence, native rich text, formula caches, and the previous cell style in either workbook model

Delete and ClearSelectedRange clear the entire selection, Ctrl+C and CopySelectedRange copy tab-separated Unicode text, and Ctrl+V and PasteSelectedRange paste clipboard text at the selection's top-left cell; PasteText accepts the same text directly

Every target is checked before a write starts, including protected blank cells and effective XLSX styles inherited from rows, columns, or overlays; a rejected target turns down the whole operation, and a formula-entry exception restores the captured content before it propagates

Text paste accepts tabs, CRLF or LF row breaks, quoted fields, doubled quotes, and quoted multiline text; ragged rows are padded out with blank fields, a final row break does not add a row, empty text represents one blank cell, and a leading apostrophe keeps literal text

Existing array formulas and data-table regions reject content edits, partial merged-range clears reject the whole operation, and a multi-cell paste into a merge is turned away; single merged-anchor edits and clears containing the whole merge preserve its geometry

The single-cell editing hooks are typed callbacks: OnBeforeEdit (a TXLSViewerBeforeEditEvent) receives the proposed text and can veto or rewrite it through Allow and Text, and OnAfterEdit (a TXLSViewerAfterEditEvent) reports the committed text; a single-cell Delete keeps these hooks, whilst range clear and paste operate through the headless transaction API without invoking cell editing callbacks

Viewer.Editable := True;
Viewer.GoToCell(2, 3);
Viewer.FormulaBarText := '=A1*2';
Viewer.Undo;
Viewer.Redo;

Headless editing transactions

TXLSWorkbookEditHistory in lxWorkbookViewer provides the same transaction engine without building a control; bind a borrowed classic or XLSX workbook, then call EditCell, ClearRange, CopyRangeText, PasteText, Undo, or Redo with one-based sheet, row, and column coordinates

ClearHistory releases retained undo and redo transactions and resets LastTransaction; it preserves the bound workbook and its current cell content

Every stack entry is a TXLSWorkbookEditTransaction record carrying the sheet index, a sheet identity token, inclusive FirstRow/FirstCol/LastRow/LastCol bounds, and a TXLSCellContentSnapshotArray of the captured TXLSCellContentSnapshot values; both history stacks have type TXLSWorkbookEditTransactionArray

CanEditRange, copying, and preflight do not create blank cells or materialise packed XLSX storage; successful edits may materialise the stored cells they change, and the caller keeps workbook ownership and must detach or destroy the history before freeing the workbook

The headless engine restores formula cache states without evaluating formulas; invoke the workbook's Recalculate after a successful operation when updated calculated results are required, whilst the viewer does this automatically once per operation

MaxOperationCells defaults to 100000 and accepts 1 through 1000000; UndoLimit defaults to 100, accepts 0 through 100000, and empties both history stacks when changed, with zero disabling history; clipboard text is limited to 16 Mi characters

LastTransaction exposes the most recent successful operation's sheet and bounds without revealing the stored history payload; a blocked undo or redo leaves its stack entry available for a later attempt

Undo and redo recheck current protection and structural bounds, rejecting a changed worksheet identity or an array, data table, or merge reaching beyond the transaction; externally recalculated spills can therefore block a history operation until their intersecting bounds become editable

History := TXLSWorkbookEditHistory.Create;
try
  History.Bind(Workbook);
  if History.PasteText(1, 2, 1, '42'#9'TRUE'#13#10'''literal'#9'=A2*2') then
    Workbook.Recalculate;
  if History.Undo then
    Workbook.Recalculate;
finally
  History.Free;
end;

Range and Reference Selection

Use Shift navigation, mouse dragging, or SelectRange to create a rectangular selection exposed through SelectionTop, SelectionLeft, SelectionBottom, SelectionRight, and SelectedRange

BeginReferencePick enables formula-reference mode and OnReferencePick (a TXLSViewerReferenceEvent) publishes the current A1 range whenever the selection changes; call EndReferencePick when the host formula editor has accepted the reference

Display Properties

Check the configuration controls below