Formula auditingSpreadsheet
Trace precedents and dependents with arrows, select them by keyboard, step through a formula with the Evaluate Formula dialog, and review the cells the error checker marks.
Precedents and dependents#
getPrecedents(address) lists the cells and ranges a formula reads directly, and getDependents(address) lists the formulas that read a cell directly. Ranges come back as B2:E2. References on other sheets are prefixed, as in 'Q3 Budget'!E5. Defined names and table references are resolved to the ranges they point at.
sheet.getPrecedents('F2'); // ['B2:E2', 'Rates!B1']
sheet.getDependents('B2'); // ['F2', 'Summary!C4']Arrows#
tracePrecedents(address?) and traceDependents(address?) draw blue arrows on the grid, like the Excel commands of the same name. Without an address they use the active cell. Each call traces one more level, so calling it again follows the chain further back or forward. A box marks a precedent range, and a dashed arrow with a sheet marker points to a reference on another sheet. clearArrows() removes them all. The arrows follow scrolling and are hidden from screen readers. The live region announces how many cells were traced instead.
The cell context menu has Trace precedents, Trace dependents and Remove arrows. Ctrl + [ selects the direct precedents on the current sheet, and Ctrl + ] selects the direct dependents.
Evaluate Formula#
evaluateFormulaSteps(address) returns the steps Excel's Evaluate Formula dialog shows. Each step gives the whole formula so far, the part about to be evaluated (evaluated) and what that part becomes (value). The last step holds the result.
sheet.setFormula('F3', '=IF(B3>5000,"Over budget",B3*1.1)');
sheet.evaluateFormulaSteps('F3');
// [{ formula: '=IF(B3>5000,"Over budget",B3*1.1)', evaluated: 'B3', value: '7200' },
// { formula: '=IF(7200>5000,"Over budget",B3*1.1)', evaluated: '7200>5000', value: 'TRUE' },
// { formula: '=IF(TRUE,"Over budget",B3*1.1)', evaluated: 'IF(TRUE,"Over budget",B3*1.1)', value: '"Over budget"' },
// { formula: '"Over budget"', evaluated: '', value: '"Over budget"' }]The leftmost, innermost part is evaluated first. Cell references are replaced by their values. A range used as an operand becomes an array constant such as {5400,6100}, cut short after 60 items. A range passed straight to a function stays a range, so the function step evaluates the whole call. IF and IFERROR evaluate only the branch they take, and LET and LAMBDA are evaluated in one step.
openDialog('evaluateFormula'), or Evaluate formula… in the context menu, opens the dialog for the active cell. The part to be evaluated next is underlined, Evaluate moves forward one step, and the status line announces each result.
Error checking#
A small green triangle in the leading top corner marks a cell that looks like a mistake. Three checks run on every cell that is drawn:
| Check | A cell is marked when | Offered correction |
|---|---|---|
| Number stored as text | It holds text that reads as a number, such as 18, -4.5, 1e3 or 12.5%, with or without leading zeros. |
Convert to number |
| Inconsistent formula | The cells on both sides of it, or above and below it, share one formula pattern and its own pattern differs. Patterns are compared in R1C1 form, so =B2+C2 and =B4+C4 are the same pattern. |
Use the neighbouring formula |
| Formula omits adjacent cells | It is one of SUM, AVERAGE, COUNT, COUNTA, MIN, MAX, PRODUCT, MEDIAN, STDEV or VAR over a single row or column range, and a typed number sits directly before or after that range. |
Include the adjacent cells |
Select a marked cell and a button appears beside it. Click it, or press Alt + Shift + F10, for a menu that names the problem, offers the correction and has Ignore error. A correction is one undo step. A screen reader hears the problem as part of the cell's name, for example "C5, 18, possible error: Number stored as text".
Ignore error stores the cell and the kind of check in the sheet's ignoredErrors. The entry follows inserted and deleted rows and columns, is undone like any other edit, and is saved to xlsx as an ignoredErrors element, which is what Excel writes, so a cell ignored here stays unmarked in Excel and the other way round. The six kinds of check Excel has and this component does not run (evalError, twoDigitTextYear, emptyCellReference, listDataValidation, calculatedColumn, unlockedFormula) are read and written back unchanged.
sheet.getErrorChecks(); // [{ address: 'D3', kind: 'formula', suggestion: '=B3+C3' }, …]
sheet.ignoreError('D3'); // ignores the check that marks D3
sheet.ignoreError('B8', 'numberStoredAsText'); // names the kind, marked or notignoreError takes one cell. Set errorChecking: false to switch the checks, the markers and the button off.
Not checked: formulas that refer to empty cells, unlocked formula cells, two-digit years in text, and formulas in table columns that differ from the column formula. Error values such as #DIV/0! are styled as errors but get no marker.