HotXLS Docs

Workbook Viewer Feature

Overview

In addition to file manipulation, Delphi and Lazarus desktop applications often need to display and edit workbooks; HotXLS includes a visual VCL and LCL control that renders either workbook model directly

TXLSWorkbookViewer Control

The TXLSWorkbookViewer component provides scrolling, rectangular selection, editing, formula input, comments, hyperlinks, conditional formatting, and print preview without creating 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 accepts .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 while 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 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 restores 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 rejects the entire 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 with blank fields, a final row break does not add a row, empty text represents one blank cell, and a leading apostrophe stores 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 rejected; 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 retains these hooks, while 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 creating 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

Each stack entry is a TXLSWorkbookEditTransaction record holding 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 materialize packed XLSX storage; successful edits may materialize the stored cells they change, and the caller retains workbook ownership and must detach or destroy the history before freeing the workbook

The headless engine restores formula cache states without evaluating formulas; call the workbook's Recalculate after a successful operation when updated calculated results are required, while 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 clears 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 exposing 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 that extends 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