Hi,
Thank you for your patience while we consulted our development team regarding your use case (Internal Track ID: SJS-36022).
We have received direct feedback and architectural guidance from the development team regarding both the Collaboration Add-on and the standalone snapshot/event-driven approaches. Please find the detailed findings and recommendations below:
Built-in Workbook Comparison API
Official Status: SpreadJS currently does not provide a built-in public API (such as Workbook.compare(versionA, versionB)) that takes two independently saved .sjs or JSON workbooks and outputs an operational delta.
Generating a Google Sheets–style visual diff with automatic change highlighting requires an application-level implementation.
Follow-Up Questions on the Collaboration Add-on
Client-Side-Only Usage (Without Collaboration Server):
Yes, the Collaboration Add-on can be used entirely on the client side to capture and replay ChangeSets locally without needing the Collaboration Server. The official documentation includes an example demonstrating local persistence using localStorage: https://developer.mescius.com/spreadjs/docs/spreadjs-collaboration-server/spreadjs-sheets-collaboration/spreadjs-sheets-collaboration-add-on
Compatibility with fromJSON() and .sjs Snapshots:
While fromSnapshot() can load standard workbook JSON, ChangeSets strictly depend on internal document and sheet identifiers established during the collaboration session.
Therefore, previously recorded ChangeSets cannot be reliably applied across workbooks restored via standard fromJSON() / .sjs unless they originate from the matching Collaboration Snapshot (toSnapshot() / fromSnapshot()).
Additionally, existing historical revisions saved only as .sjs/JSON snapshots cannot retroactively be reconstructed into original ChangeSets.
Inspecting Operations inside a ChangeSet:
Through onChangeSet(), you can persist ChangeSets for replay, and the public interface exposes the operation list and high-level OpType.
However, there is no public, stable schema designed to extract granular cell coordinates (sheet, row, column), old values, new values, or style diffs across all operation types. ChangeSets are strictly designed for the Operational Transformation (OT) replay engine rather than human-readable diff reporting.
Events During applyChangeSet() Replay:
Standard UI events (such as CellChanged and ValueChanged) are not guaranteed to fire across workbook model replays during applyChangeSet() and cannot be relied upon to paint visual highlights during replay.
Event-Driven & Programmatic Coverage
Programmatic API Calls:
Standard calls such as sheet.setValue() and sheet.setFormula() can raise the CellChanged event. Routing every setter through spread.commandManager().execute() is therefore not a strict requirement for basic event firing.
Full Coverage Considerations:
While basic edits raise events, listening exclusively to commands or event listeners does not automatically guarantee 100% complete tracking across all complex operations.
Any event-driven tracking approach must be carefully tailored and validated against the specific workbook features, operations, and dataset sizes your application supports.
Recommended Architectural Approaches
Based on the development team’s recommendations, here are the two viable paths depending on your workflow:
Path A: For Existing / Independent Workbook Snapshots (.sjs / JSON) (Recommended for your current setup)
If your application already manages versions as independent snapshots loaded via fromJSON() or .sjs:
Application-Level State Comparator:
Load the previous version and current version into memory.
Compare structural elements first:
Sheets: Added, removed, or renamed sheets (using stable sheet keys/names).
Rows / Columns: Compare row and column counts or structural definitions to detect insertions and deletions.
Compare content within active/used ranges:
Cell values and formulas via sheet.getValue() / sheet.getFormula().
Cell formatting/styles via sheet.getStyle().
Dedicated Highlighting Layer:
Once your comparator produces a diff list, render visual highlights on the active preview sheet:
Use cell styles/background colors or border indicators for modified cells.
Use custom indicators (such as header markers or subtle row/column highlights) for inserted/deleted ranges.
Path B: For Future Version History Using the Collaboration Add-on
If you plan to redesign the versioning pipeline from scratch:
Store an initial Collaboration Snapshot (toSnapshot()), capture and store sequential ChangeSets via onChangeSet(), and periodically save new snapshots for fast milestone loading.
Store your own metadata (author, timestamp, version tag) alongside each ChangeSet milestone.
For change descriptions and visual highlighting, development recommends either:
Comparing restored workbook states (as described in Path A) between milestone snapshots, or
Recording structured change metadata in your application layer as actions occur, rather than trying to parse raw OT operations.
Regards,
Priyam