ws.whatIf
WorksheetWhatIf
Sub-API for What-If analysis operations.
2 methods
goalSeek
→ Promise<GoalSeekResult>goalSeek(targetCell: string, targetValue: number, changingCell: string): Promise<GoalSeekResult>;| Parameter | Type | Required |
|---|---|---|
| targetCell | string | required |
| targetValue | number | required |
| changingCell | string | required |
Find the input value that makes a formula produce a target result (Excel's "Goal Seek" equivalent). Use this to back-solve for an unknown assumption — e.g., find the discount rate that produces a specific NPV, or the growth rate needed to hit a revenue target. Example — find WACC that yields NPV = 0: ``` // B1 = WACC assumption, B5 = =NPV(B1, C10:C20) const result = await ws.whatIf.goalSeek('B5', 0, 'B1'); if (result.found) { await ws.cells.setCellValue('B1', result.solutionValue); } ``` The method is read-only — the changing cell is restored after evaluation. Call setCellValue() yourself to apply the solution. @param targetCell - A1 address of the cell containing the formula to evaluate @param targetValue - The desired result value @param changingCell - A1 address of the input cell to vary @returns GoalSeekResult with solutionValue if found
dataTable
→ Promise<DataTableResult>dataTable(
formulaCell: string,
options: {
rowInputCell?: string | null;
colInputCell?: string | null;
rowValues: (string | number | boolean | null)[];
colValues: (string | number | boolean | null)[];
},
): Promise<DataTableResult>;| Parameter | Type | Required |
|---|---|---|
| formulaCell | string | required |
| options | { rowInputCell?: string | null; colInputCell?: string | null; rowValues: (string | number | boolean | null)[]; colValues: (string | number | boolean | null)[]; } | required |
Compute a sensitivity/scenario table by evaluating a formula with different input values (Excel's "What-If Data Table" equivalent). Use this for DCF sensitivity tables, LBO return grids, or any two-dimensional parameter sweep. One-variable table: provide either `rowInputCell` or `colInputCell`. Two-variable table: provide both. Example — 2D sensitivity grid (WACC x Terminal Growth Rate): ``` // B1 = WACC assumption (e.g. 0.10) // B2 = Terminal growth rate (e.g. 0.025) // B3 = =NPV(B1, C10:C20) + terminal_value (the formula to sweep) const result = await ws.whatIf.dataTable('B3', { rowInputCell: 'B1', colInputCell: 'B2', rowValues: [0.08, 0.09, 0.10, 0.11, 0.12], colValues: [0.015, 0.020, 0.025, 0.030, 0.035], }); // result.results is a 5x5 grid of NPV values // Write to sheet: iterate result.results and call setCells() ``` Input cells must already contain a value before calling this method. The method is read-only — input cells are restored after evaluation. @param formulaCell - A1 address of the cell containing the formula to evaluate @param options - Input cells and substitution values @returns 2D grid of computed results (DataTableResult)