Loading...
Loading...
Headless spreadsheet engine for financial modeling, data analysis, and scenario comparison. Use when: building financial models with ratios and what-if scenarios, computing derived values from tabular data with formulas, producing .xlsx files with live formulas (not static values) for human review, any task where the agent would otherwise write imperative code to manipulate numbers that a spreadsheet does naturally. Triggers: financial model, scenario analysis, ratio computation, balance sheet, P&L, what-if, sensitivity analysis, banking ratios, spreadsheet model, build a model, projection, forecast. Do NOT use for: simple CSV/Excel read/write (use the xlsx skill), chart-only tasks, or data volumes exceeding ~5000 rows.
npx skill4agent add marcfargas/skills sheet-modelxlsx| Task | Use |
|---|---|
| Read/write/edit existing .xlsx files | |
| Clean messy CSV data into a spreadsheet | |
| Build a financial model with formulas and scenarios | this skill |
| Produce a .xlsx where formulas are live and editable | this skill |
| Compute ratios, projections, what-if analysis | this skill |
cd {baseDir}
npm installAgent code (declarative) SheetModel wrapper Output
──────────────────────── ────────────────────────── ──────────────
addRow('Revenue', 701384) → HyperFormula (compute) → Console table
addRow('EBITDA', formula) → Named ranges auto-tracked → .xlsx with live
addScenarioSheet(config) → {Name} refs resolved → formulas +
getValue('EBITDA') → Dependency graph updates → styling +
exportXlsx('model.xlsx') → ExcelJS (export) → cond. format.mjsimport { SheetModel } from '{baseDir}/lib/sheet-model.mjs';
const M = new SheetModel();M.addSheet('Data');
// Section headers (bold, no value)
M.addSection('Data', 'BALANCE SHEET');
M.addBlank('Data');
// Data rows — addRow returns the A1 row number (use it in SUM ranges)
const r_first = M.addRow('Data', ' Revenue', 701384, { name: 'Revenue' });
const r_costs = M.addRow('Data', ' Costs', -450000, { name: 'Costs' });
const r_other = M.addRow('Data', ' Other', 5000);
// Formula rows — use returned row numbers for SUM ranges
M.addRow('Data', ' EBITDA', `=SUM(B${r_first}:B${r_other})`, { name: 'EBITDA' });
// Formula rows using named references (auto-resolved by HyperFormula)
M.addRow('Data', ' Margin', '=EBITDA/Revenue', { name: 'Margin' });Build top-to-bottom: Names must be defined before any formula that references them. Define data rows first, then formulas.andaddBlank()also return the A1 row number (useful for SUM range boundaries).addSection()
| Need | Use | Why |
|---|---|---|
| Row numbers: | Ranges need cell references; named expressions resolve to single cells |
| Arithmetic between specific cells | Named expressions: | Cleaner, self-documenting |
| Mixed | Both: | Combine as needed |
=SUM(Revenue:OtherIncome){ name: 'Revenue' }addRowRevenuecell.names⚠️ Names are global across all sheets. Usingin two different sheets overwrites the first. Use unique, prefixed names for multi-sheet models:{ name: 'Revenue' },{ name: 'Rev2024' }.{ name: 'Rev2025' }
ACPCR1C1A1AdjPCTotalACCurrentAssetsACPCCAaddRowM.addRow('CashFlow', ' From Operations', '={PnL.NetIncome} + {PnL.Depreciation}');Thissyntax only works in{Sheet.Name}formulas, NOT in scenario output formulas. For scenarios, use named expressions (bare names) — they are global across sheets.addRow
M.addScenarioSheet('Scenarios', {
inputs: [
{ name: 'GrowthRate', label: 'Revenue Growth %' },
{ name: 'CostCut', label: 'Cost Reduction' },
],
scenarios: [
{ label: 'Base Case', values: {} }, // all inputs = 0
{ label: 'Optimistic', values: { GrowthRate: 0.10, CostCut: 50000 } },
{ label: 'Conservative', values: { GrowthRate: 0.03, CostCut: 20000 } },
],
outputs: [
// {InputName} → column-relative (B2, C2, D2...)
// DataSheetName → named expression from Data sheet (fixed)
// {PriorOutput} → column-relative ref to earlier output in this sheet
{ name: 'AdjRev', label: 'Adj. Revenue', format: 'number',
formula: 'Revenue * (1 + {GrowthRate})' },
{ name: 'AdjCost', label: 'Adj. Costs', format: 'number',
formula: 'Costs + {CostCut}' },
{ name: 'AdjEBITDA', label: 'EBITDA', format: 'number',
formula: '{AdjRev} + {AdjCost}' },
// Section separator
{ section: true, label: 'RATIOS' },
// Ratio with conditional formatting thresholds
{ name: 'EBITDAm', label: 'EBITDA Margin', format: 'percent',
formula: '{AdjEBITDA} / {AdjRev}',
thresholds: { good: 0.15, bad: 0.08 } },
// Inverted threshold (lower = better)
{ name: 'DebtEBITDA', label: 'Debt/EBITDA', format: 'ratio',
formula: 'TotalDebt / {AdjEBITDA}',
thresholds: { good: 2.5, bad: 4.0, invert: true } },
],
});Do NOT callbeforeaddSheet()— it creates the sheet internally. Only useaddScenarioSheet()for data sheets.addSheet()is a one-shot call. You cannot add rows to a scenario sheet after creation. Include all inputs, outputs, and sections in the config object.addScenarioSheetEvery output you want to reference later MUST have aproperty. Without it,namein a subsequent formula will throw an error.{ThatOutput}
outputs[].formula| Syntax | Resolves to | Example |
|---|---|---|
| Column-relative cell ref to scenario input row | |
| Column-relative cell ref to prior output in same sheet | |
| HyperFormula named expression (global, from any sheet) | |
{}{Wrapped}⚠️ Name collision rule: If a scenario outputmatches a Data sheet named expression,{name}will resolve to the Data sheet's fixed cell, not the scenario output's column-relative cell. Always use unique names for scenario outputs. Example: Data sheet has{OutputName}, scenario should use{ name: 'EBITDA' }— never both{ name: 'AdjEBITDA' }.EBITDA
| Format | Excel numFmt | Display |
|---|---|---|
| | |
| | |
| | |
| | |
thresholds: { good: 0.15, bad: 0.08 } // Higher is better (green >= 0.15, red < 0.08)
thresholds: { good: 2.5, bad: 4.0, invert: true } // Lower is better (green <= 2.5, red > 4.0)// From Data sheet (by named ref)
const ebitda = M.getValue('Data', 'EBITDA');
// From Scenarios (by scenario index, 0-based)
const baseEBITDA = M.getScenarioValue('Scenarios', 0, 'AdjEBITDA');
const optEBITDA = M.getScenarioValue('Scenarios', 1, 'AdjEBITDA');
// Raw cell access (sheet, col 0-indexed, a1Row 1-indexed)
const val = M.getCellValue('Data', 1, 5); // col B, row 5Usefor data sheets,getValue()for scenario sheets.getScenarioValue()on a scenario sheet returns the first scenario's value (column B).getValue()
// Formula errors (division by zero, etc.) return CellError objects, not exceptions
const val = M.getValue('Data', 'Margin');
if (typeof val !== 'number' || !isFinite(val)) {
console.error('Formula error:', val);
// val might be: { type: 'DIV_BY_ZERO' }, { type: 'REF' }, { type: 'NAME' }, etc.
}
// To prevent #DIV/0! in formulas, guard with IF:
M.addRow('Data', ' Margin', '=IF(Revenue=0, 0, EBITDA/Revenue)', { name: 'Margin' });
// Reference errors throw immediately during addRow/addScenarioSheet
// → Always define named rows BEFORE formulas that reference them
// → Error messages include the row label and cell reference for easy debuggingIF(denominator=0, 0, numerator/denominator)M.printScenarios('Scenarios');await M.exportXlsx('output.xlsx', {
creator: 'Agent Name',
headerColor: '1B3A5C', // Dark blue header background (ARGB hex, no #)
});Named ranges on scenario sheets point to the first scenario column (column B). They exist for cross-sheet references in Excel, not for selecting all scenarios.
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const ExcelJS = require('exceljs');
await M.exportXlsx('model.xlsx');
const wb = new ExcelJS.Workbook();
await wb.xlsx.readFile('model.xlsx');
const ws = wb.getWorksheet('Data');
// Custom column widths, borders, fills, page setup, etc.
ws.pageSetup = { orientation: 'landscape', fitToPage: true, fitToWidth: 1 };
ws.getColumn(2).numFmt = '$#,##0';
await wb.xlsx.writeFile('model.xlsx');import { SheetModel } from '{baseDir}/lib/sheet-model.mjs';
const M = new SheetModel();
M.addSheet('Data');
// ── Balance Sheet ──
M.addSection('Data', 'BALANCE SHEET');
M.addBlank('Data');
const r1 = M.addRow('Data', ' Cash', 50000, { name: 'Cash' });
const r2 = M.addRow('Data', ' Receivables', 120000, { name: 'Receivables' });
const r3 = M.addRow('Data', ' Inventory', 30000);
M.addRow('Data', ' Current Assets', `=SUM(B${r1}:B${r3})`, { name: 'CurrentAssets' });
M.addBlank('Data');
const r4 = M.addRow('Data', ' Payables', 80000, { name: 'Payables' });
const r5 = M.addRow('Data', ' Short-term Debt', 40000, { name: 'STDebt' });
M.addRow('Data', ' Current Liabilities', `=SUM(B${r4}:B${r5})`, { name: 'CurrentLiab' });
M.addBlank('Data');
M.addRow('Data', ' Equity', 200000, { name: 'Equity' });
M.addRow('Data', ' Long-term Debt', 150000, { name: 'LTDebt' });
// ── P&L ──
M.addBlank('Data');
M.addSection('Data', 'INCOME STATEMENT');
M.addBlank('Data');
const p1 = M.addRow('Data', ' Revenue', 500000, { name: 'Revenue' });
const p2 = M.addRow('Data', ' COGS', -200000);
const p3 = M.addRow('Data', ' Operating Exp', -150000);
const p4 = M.addRow('Data', ' Depreciation', -30000, { name: 'Depreciation' });
M.addRow('Data', ' Operating Income', `=SUM(B${p1}:B${p4})`, { name: 'OpIncome' });
M.addRow('Data', ' Interest Expense', -15000, { name: 'IntExp' });
M.addRow('Data', ' Net Income', '=OpIncome+IntExp', { name: 'NetIncome' });
// ── Scenarios ──
M.addScenarioSheet('Analysis', {
inputs: [
{ name: 'RevGrowth', label: 'Revenue Growth' },
{ name: 'DebtPaydown', label: 'Debt Paydown' },
],
scenarios: [
{ label: 'As-Is', values: {} },
{ label: 'Growth 10%', values: { RevGrowth: 0.10 } },
{ label: 'Deleverage', values: { RevGrowth: 0.05, DebtPaydown: 50000 } },
],
outputs: [
{ name: 'AdjRev', label: 'Adj. Revenue', format: 'number',
formula: 'Revenue * (1 + {RevGrowth})' },
{ name: 'AdjEBITDA', label: 'EBITDA', format: 'number',
formula: '{AdjRev} + (Revenue - OpIncome + Depreciation) / Revenue * {AdjRev} * -1 + ABS(Depreciation)' },
{ name: 'TotalDebt', label: 'Total Debt', format: 'number',
formula: 'LTDebt + STDebt - {DebtPaydown}' },
{ name: 'NetDebt', label: 'Net Debt', format: 'number',
formula: '{TotalDebt} - Cash' },
{ section: true, label: 'KEY RATIOS' },
{ name: 'CurrRatio', label: 'Current Ratio', format: 'ratio',
formula: 'CurrentAssets / CurrentLiab',
thresholds: { good: 1.5, bad: 1.0 } },
{ name: 'DebtEBITDA', label: 'Debt/EBITDA', format: 'ratio',
formula: '{TotalDebt} / {AdjEBITDA}',
thresholds: { good: 2.5, bad: 4.0, invert: true } },
{ name: 'ICR', label: 'Interest Coverage', format: 'ratio',
formula: '{AdjEBITDA} / ABS(IntExp)',
thresholds: { good: 3.0, bad: 1.5 } },
{ name: 'EBITDAm', label: 'EBITDA Margin', format: 'percent',
formula: '{AdjEBITDA} / {AdjRev}',
thresholds: { good: 0.20, bad: 0.10 } },
{ name: 'ROE', label: 'Return on Equity', format: 'percent',
formula: 'NetIncome / Equity',
thresholds: { good: 0.12, bad: 0.05 } },
],
});
// Use
M.printScenarios('Analysis');
console.log('EBITDA (Growth):', M.getScenarioValue('Analysis', 1, 'AdjEBITDA'));
await M.exportXlsx('financial-model.xlsx');const M = new SheetModel();
M.addSheet('Loan');
M.addSection('Loan', 'LOAN PARAMETERS');
M.addBlank('Loan');
M.addRow('Loan', 'Principal', 500000, { name: 'Principal' });
M.addRow('Loan', 'Annual Rate', 0.05, { name: 'AnnualRate' });
M.addRow('Loan', 'Years', 20, { name: 'Years' });
M.addRow('Loan', 'Monthly Rate', '=AnnualRate/12', { name: 'MonthlyRate' });
M.addRow('Loan', 'Periods', '=Years*12', { name: 'Periods' });
M.addBlank('Loan');
// PMT returns negative (cash outflow) — negate for display
M.addRow('Loan', 'Monthly Payment', '=-PMT(MonthlyRate, Periods, Principal)', { name: 'Payment' });
M.addRow('Loan', 'Total Interest', '=Payment*Periods - Principal', { name: 'TotalInterest' });
await M.exportXlsx('loan-model.xlsx');cell.names = ['Name']definedNames.add()addEx()add()InvFinCPaddEx()getCellFormula()"=SUM(...)"={ formula: 'SUM(...)' }==#NAME?SUMABSIFxlsxaddRowM.hf.setCellContents(...)#,##0formatACR1C1A1RevenueOpIncome`=SUM(B${r1}:B${r3})`