HotXLS Docs

SaveSemanticSnapshot and ComputeSemanticHash methods

Streams a versioned canonical representation of workbook semantics or computes the SHA-256 of exactly those bytes

Syntax

procedure SaveSemanticSnapshot(AStream: TStream); overload;
procedure SaveSemanticSnapshot(AStream: TStream;
  AProfile: TXLSSemanticSnapshotProfile;
  AOptions: TXLSSemanticSnapshotOptions); overload;

function ComputeSemanticHash: WideString; overload;
function ComputeSemanticHash(
  AProfile: TXLSSemanticSnapshotProfile;
  AOptions: TXLSSemanticSnapshotOptions): WideString; overload;

The methods are exposed by Classic IXLSWorkbook and TXLSWorkbook in lxHandle, and by TXLSXWorkbook in lxHandleX

The profile and option types are declared in lxSemanticSnapshot and are visible through both workbook units

Retained file payload streaming

Supported VBA storage payloads and Classic security-complete Ctls bytes stream from retained ranges without automatic editable Blob materialization; their order, unsigned 64-bit record length and complete canonical bytes remain unchanged

Explicit mutable payloads use their current length, including zero bytes; individual payload writes are at most 65536 bytes, and a payload beyond MaxInt can be emitted without first converting it into a signed-32-bit Blob

Allocation behavior still depends on workbook metadata, actual editable source text and the caller's destination; a TMemoryStream destination may allocate for the entire snapshot, while ComputeSemanticHash consumes the same bytes through its incremental hash stream

The writer's WriteFileStream(ATag: Word; ASource: TXLSFileStream) emits an existing canonical bytes field and retains caller ownership; ordinary workbook callers should continue using the public snapshot/hash entry points

Destination I/O can leave partial output and propagates its error; discard that failed writer and use a fresh writer for retrying against the unchanged source

Missing input, invalid tags, finished writers and positive payloads without backing refuse; no temporary file remains after the qualified success and failure cases

See streamed payload qualification for the complete above-MaxInt hash, public VBA composition and allocator scope

Profiles

ValueMeaning
xlsspContentCanonical workbook content suitable for ordinary semantic identity checks
xlsspSecurityCompleteContent plus supported opaque security and preservation state that is intentionally excluded from ordinary content identity

Options

ValueIncluded state
xlssoIncludeViewerStateSelections, active-view state, and other supported viewer-facing state
xlssoIncludeVolatileMetadataSupported timestamps, producer metadata, and other intentionally volatile fields
xlssoIncludeFormulaCachedResultsStored formula results and supported external-link caches without recalculation or external I/O

The option set has type TXLSSemanticSnapshotOptions = set of TXLSSemanticSnapshotOption. The parameterless overloads use xlsspContent with an empty option set

Streaming and identity rules

Modern cell features

TXLSSemanticCellStyle.CellControlKind has type TXLSSemanticCellControlKind with xlssControlNone, xlssControlUnknown and xlssControlCheckbox; CellControlDefaultState has type TXLSSemanticCheckboxDefaultState with xlssCheckboxUnchecked, xlssCheckboxChecked and xlssCheckboxBlank

XLSX style reads resolve direct and inherited controls without creating cells; canonical style serialization rejects xlssControlUnknown instead of treating an unknown property bag as a plain cell

Snapshots and hashes include normalized effective control rectangles, merging adjacent equal regions without expanding whole columns into cells; unrelated non-default style overlays retain their existing unsupported-normalization boundary

TXLSXWorkbook.ReadSemanticFeatures(xlsxSemanticCellImages, Sheet, AMaxBytes, AMaxItems) returns detached entries keyed by cell address, including exact encoded PNG or JPEG bytes, content type, alternative text and decorative metadata; quotas cover canonical bytes and image entries, and oversized payloads are rejected before copying

Workbook comparison includes these image definitions when lcoDrawings is selected, while lcoCellStyles and lcoBlankStyleRegions include effective Checkbox formats; matching fallback errors alone do not make distinct images equal

Unknown rich-value image graphs raise EXLSSemanticSnapshot during selected feature comparison or snapshot traversal; these operations retain the workbook read lease and do not calculate inspected cells

Concurrency and errors

Both methods hold a workbook read lease for the complete traversal

A concurrent public mutation fails before changing workbook state with EXLSWorkbookWriteGuardUnavailable, while a detected generation change or unsupported ambiguous semantic structure raises EXLSSemanticSnapshot

Delphi example

var
  Snapshot: TFileStream;
  Hash: WideString;
begin
  Snapshot:= TFileStream.Create('workbook.semantic', fmCreate);
  try
    Workbook.SaveSemanticSnapshot(Snapshot,
      xlsspSecurityComplete,
      [xlssoIncludeFormulaCachedResults]);
  finally
    Snapshot.Free;
  end;

  Hash:= Workbook.ComputeSemanticHash;

C++Builder example

TFileStream *snapshot = new TFileStream(
  L"workbook.semantic", fmCreate);
try
{
  workbook->SaveSemanticSnapshot(snapshot);
}
__finally
{
  delete snapshot;
}

WideString hash = workbook->ComputeSemanticHash();

Snapshot model reference

The snapshot engine is not tied to workbook objects: everything below is declared in lxSemanticSnapshot, and the workbook methods are thin wrappers over the same global entry points

Extension interfaces

Implement IXLSSemanticWorkbookSource to emit or hash a snapshot of any source, and optionally IXLSSemanticFormulaResolver so emitted formulas carry resolved external-reference and defined-name information

IXLSSemanticWorkbookSource = interface
  procedure WriteCommon(AWriter: TXLSSemanticCanonicalWriter);
end;

IXLSSemanticFormulaResolver = interface
  function ResolveFormulaReference(AExternID: Integer;
    out AInfo: TXLSSemanticFormulaReferenceInfo): Boolean;
  function ResolveFormulaName(ANameID, AExternID: Integer;
    out AInfo: TXLSSemanticFormulaNameInfo): Boolean;
end;

TXLSSemanticFormulaReferenceInfo = record
  LinkKind: TXLSSemanticFormulaLinkKind;
  BookName: WideString;
  FirstSheetName: WideString;
  LastSheetName: WideString;
end;

TXLSSemanticFormulaNameInfo = record
  NameKind: TXLSSemanticFormulaNameKind;
  LinkKind: TXLSSemanticFormulaLinkKind;
  Name: WideString;
  ScopeSheetName: WideString;
  BookName: WideString;
end;

Inside WriteCommon the writer is an opaque handle: do not call its primitive methods — BeginContainer / EndContainer frame a tagged container and WriteNull, WriteBoolean, WriteUInt32, WriteUInt64, WriteInt32, WriteInt64, WriteBinary64, WriteWideString, and WriteBytes encode one canonical primitive each, with Finish sealing the stream and Finished reporting completion — pass it back into the emission helpers below so every producer emits identical bytes

Entry-point globals

procedure XLSSaveSemanticSnapshot(AStream: TStream;
  const ASource: IXLSSemanticWorkbookSource;
  AProfile: TXLSSemanticSnapshotProfile;
  AOptions: TXLSSemanticSnapshotOptions);
function XLSComputeSemanticHash(
  const ASource: IXLSSemanticWorkbookSource;
  AProfile: TXLSSemanticSnapshotProfile;
  AOptions: TXLSSemanticSnapshotOptions): WideString;
procedure XLSInitializeSemanticCellStyle(out AStyle: TXLSSemanticCellStyle);
function XLSBuiltinSemanticNumberFormat(AId: Word): WideString;

XLSInitializeSemanticCellStyle fills a style record with the canonical defaults before individual fields are edited; XLSBuiltinSemanticNumberFormat maps a builtin number-format id (below 164) to its format string, which consumers need to interpret emitted styles and decoded streams

Model vocabulary

GroupTypes
SheetTXLSSemanticSheetKind (worksheet, macro, chart, VBA, unknown), TXLSSemanticSheetVisibility (visible, hidden, very hidden), TXLSSemanticDefinedNameScope (workbook or worksheet), TXLSSemanticRange / TXLSSemanticRanges (rectangular ranges used by merges, conditional formats, and tables)
CellTXLSSemanticCellKind (blank, number, datetime, text, boolean, error, formula)
StyleTXLSSemanticCellStyle (complete canonical cell style), TXLSSemanticColor with TXLSSemanticColorKind (none, automatic, system, ARGB, theme, indexed) and a tint, TXLSSemanticBorderEdge / TXLSSemanticBorderStyle, TXLSSemanticFillPattern, TXLSSemanticGradientKind / TXLSSemanticGradientStop / TXLSSemanticGradientStops, TXLSSemanticUnderline, TXLSSemanticFontVerticalAlign
FormulaTXLSSemanticFormulaEncoding (parsed tree versus opaque text), TXLSSemanticFormulaArrayKind (none, CSE, dynamic), TXLSSemanticFormulaNodeKind, TXLSSemanticFormulaRangeKind, TXLSSemanticFormulaLinkKind (same sheet, internal, external, add-in, DDE, OLE, other), TXLSSemanticFormulaNameKind
Drawing and chartsTXLSSemanticDrawingKind (image, textbox, chart, group, form control), TXLSSemanticDrawingAnchorMode (move and size, move only, absolute), TXLSSemanticImageFormat, TXLSSemanticChartFamily

Emission helpers

These globals write one model fragment into the writer passed to WriteCommon: XLSWriteSemanticLiteralCell, XLSWriteSemanticCellStyle, XLSWriteSemanticColor, XLSWriteSemanticRanges, XLSWriteSemanticMerge, XLSWriteSemanticAxisEntry, XLSWriteSemanticFormulaTree, XLSWriteSemanticFormulaDefinition, and XLSWriteSemanticFormulaCell (formula cells carry array bounds and an optional cached result). XLSWriteSemanticWorkbookCommon opens the workbook container and invokes WriteCommon, which custom sources normally call first

Computed trendline text

OOXML trendline records emit EquationText and RSquaredText from represented cached data and display switches; Line uses original category positions, Scatter/Bubble uses matched numeric X, blank Y does not compact indices, and represented fixed intercepts participate

These ordinary UTF-16 properties retain the current canonical stream format; the shared computation profile describes native formatting, Moving Average empty labels, degenerate fits and remaining numerical/layout limits

See also

IXLSWorkbook interface · TXLSXWorkbook class · CreateReadOnlyView method

Uniform textbox font identity

Modern uniform textbox overrides use the existing nested font fields; each property retains its own presence, so explicit normal bold or italic differs from an unspecified value

Semantic hashes observe both presence and values, along with represented text RGB; no resolved font default is invented for missing overrides