Formula auditing

Visualize formula dependencies with trace precedents and dependents

Formula auditing allows you to visualize and understand the relationships between cells in your spreadsheet. You can trace which cells feed data into a formula (precedents) and which cells use a specific cell in their formulas (dependents).

Overview

The useSpreadsheetState hook provides three methods for auditing formula dependencies:

  • onTracePrecedents - Shows arrows from cells that the selected cell depends on

  • onTraceDependents - Shows arrows to cells that depend on the selected cell

  • onRemoveArrows - Clears all trace arrows from the display

Basic Usage

import { SpreadsheetProvider, CanvasGrid } from "@rowsncolumns/spreadsheet";
import { useSpreadsheetState } from "@rowsncolumns/spreadsheet-state";

const MySpreadsheet = () => {
  const {
    activeCell,
    activeSheetId,
    arrows,
    onTracePrecedents,
    onTraceDependents,
    onRemoveArrows,
    ...rest
  } = useSpreadsheetState({
    sheets,
    sheetData,
    onChangeSheets,
    onChangeSheetData
  });

  return (
    <div>
      <div className="toolbar">
        <button onClick={() => onTracePrecedents(activeSheetId, activeCell)}>
          Trace Precedents
        </button>
        <button onClick={() => onTraceDependents(activeSheetId, activeCell)}>
          Trace Dependents
        </button>
        <button onClick={onRemoveArrows}>
          Remove Arrows
        </button>
      </div>
      <CanvasGrid
        {...rest}
        activeCell={activeCell}
        arrowComponents={arrows}
      />
    </div>
  );
};

API Reference

onTracePrecedents

Traces and displays arrows from cells that the selected cell depends on (precedents) to the active cell.

Signature:

Parameters:

  • sheetId: number - The ID of the sheet containing the cell

  • cell: CellInterface - Object with rowIndex and columnIndex properties

Example:

If cell C6 contains the formula =SUM(A1:A5), calling onTracePrecedents on C6 will display arrows from the range A1:A5 pointing to C6, showing that C6 depends on those cells for its value.

onTraceDependents

Traces and displays arrows from the selected cell to all cells that depend on it (dependents).

Signature:

Parameters:

  • sheetId: number - The ID of the sheet containing the cell

  • cell: CellInterface - Object with rowIndex and columnIndex properties

Example:

If cell A1 contains a value and is referenced by formulas in cells C6 and D10, calling onTraceDependents on A1 will display arrows from A1 pointing to C6 and D10.

onRemoveArrows

Clears all trace arrows from the spreadsheet display.

Signature:

Parameters: None

Example:

arrows

The arrows property contains the rendered arrow components that visualize the cell dependencies. These must be passed to the CanvasGrid component via the arrowComponents prop.

Type:

Usage:

Use Cases

Debugging Complex Formulas

When working with complex spreadsheets containing many interrelated formulas, formula auditing helps you understand the data flow:

Impact Analysis

Before changing a cell value, you can see which other cells will be affected:

Interactive Formula Explorer

Create an interactive tool that lets users explore formula relationships:

Visual Styling

The arrows are rendered with default styling, but they respond to cell positions and handle both single cells and ranges:

  • Single Cell References: Arrows point from one cell to another

  • Range References: A border is drawn around the range, with an arrow pointing from the range to the dependent cell

  • Color: Default arrow color is #000000 (black)

The arrow components are absolutely positioned and overlay the grid without interfering with cell interactions.

Notes

  • Arrows are automatically cleared when you call onTracePrecedents or onTraceDependents again

  • Only call onRemoveArrows() when you want to clear all arrows completely

  • The arrows are React components that must be rendered via the arrowComponents prop

  • The tracing works with the built-in dependency graph maintained by the calculator

  • Both single cell references and range references are supported

Last updated

Was this helpful?