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
| Value | Meaning |
|---|---|
xlsspContent | Canonical workbook content suitable for ordinary semantic identity checks |
xlsspSecurityComplete | Content plus supported opaque security and preservation state that is intentionally excluded from ordinary content identity |
Options
| Value | Included state |
|---|---|
xlssoIncludeViewerState | Selections, active-view state, and other supported viewer-facing state |
xlssoIncludeVolatileMetadata | Supported timestamps, producer metadata, and other intentionally volatile fields |
xlssoIncludeFormulaCachedResults | Stored 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
SaveSemanticSnapshotwrites at the target stream's current position and does not seek, own, or free the stream- A downstream write failure can leave a prefix in the target, so callers that require atomic publication should write to a temporary target before replacing the destination
ComputeSemanticHashreturns 64 lowercase hexadecimal characters and hashes incrementally without allocating a complete snapshot buffer- The snapshot is a HotXLS semantic protocol, not an XLS, XLSX, ODS, CSV, or PDF document
- Compare snapshots or hashes only when protocol version, profile, and option set match
- The operation does not save, recalculate, refresh links, access external resources, or mutate workbook caches
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
| Group | Types |
|---|---|
| Sheet | TXLSSemanticSheetKind (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) |
| Cell | TXLSSemanticCellKind (blank, number, datetime, text, boolean, error, formula) |
| Style | TXLSSemanticCellStyle (complete canonical cell style), TXLSSemanticColor with TXLSSemanticColorKind (none, automatic, system, ARGB, theme, indexed) and a tint, TXLSSemanticBorderEdge / TXLSSemanticBorderStyle, TXLSSemanticFillPattern, TXLSSemanticGradientKind / TXLSSemanticGradientStop / TXLSSemanticGradientStops, TXLSSemanticUnderline, TXLSSemanticFontVerticalAlign |
| Formula | TXLSSemanticFormulaEncoding (parsed tree versus opaque text), TXLSSemanticFormulaArrayKind (none, CSE, dynamic), TXLSSemanticFormulaNodeKind, TXLSSemanticFormulaRangeKind, TXLSSemanticFormulaLinkKind (same sheet, internal, external, add-in, DDE, OLE, other), TXLSSemanticFormulaNameKind |
| Drawing and charts | TXLSSemanticDrawingKind (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