Version comparison

The version comparison feature allows users to compare two versions of a spreadsheet and visualize differences inline. Changes are highlighted with distinct colors for added, deleted, and modified cells.

Spreadsheet version comparison UI
Spreadsheet version comparison UI

Overview

Version comparison is useful for:

  • Tracking changes between document revisions

  • Reviewing edits before accepting them

  • Understanding what changed between snapshots

  • Collaboration workflows where multiple users edit the same document

Visual Highlighting

Change Type
Background
Text Color
Description

Added

Light green (#d0fae1)

Dark green (#046e38)

Cell exists in current version but not in previous

Deleted

Light red (#ffdbdb)

Dark red (#b21313)

Cell exists in previous version but not in current (with strikethrough)

Modified

Both colors

Red for old, green for new

Cell value or format changed

Modified Cells

When a cell is modified, both the old and new values are displayed side by side within the cell:

  • Old value: Red background with the previous formatting applied

  • New value: Green background with the current formatting applied

This applies to both value changes and format-only changes (e.g., text becoming bold).

Installation

Basic Usage

API Reference

useVersionComparison Hook

Options

Return Values

Property
Type
Description

getCellDiff

(sheetId, rowIndex, columnIndex) => CellDiff | null

Get diff for a specific cell

CellDiff Type

Detecting Different Types of Changes

Value Changes

Format Changes

Format-Only Changes

When a cell's value stays the same but formatting changes (e.g., text becomes bold):

Working with Shared Strings

If your cell data uses shared strings (ss property pointing to a shared strings map), pass the shared strings:

Cell data with shared string:

If the previous version has a different shared strings map (e.g., from a snapshot):

Working with Style References

If your cell data uses style IDs instead of inline formats, pass the cellXfs registry:

Cell data with style reference:

Comparison Summary

To display a summary of all changes:

CanvasGrid Props

Prop
Type
Description

isComparing

boolean

Enable comparison mode rendering

getCellDiff

(sheetId, row, col) => CellDiff | null

Function to get cell diff

Diff Engine Functions

For advanced use cases, you can use the diff engine functions directly:

Best Practices

  1. Snapshot Management: Store snapshots efficiently - consider only storing changed cells rather than the entire sheet.

  2. Performance: For large spreadsheets, consider lazy-loading diffs only for visible cells.

  3. User Experience:

    • Show a clear indicator when comparison mode is active

    • Provide a summary of changes

    • Allow users to navigate between changes

  4. Format Comparison: Remember that format changes count as modifications even if the value is unchanged.

Example: Full Implementation

Last updated