接手別人的試算表
有人離職了。留下一份試算表。14 個分頁,三層巢狀的 VLOOKUP 公式,一個引用了某個沒人找得到的命名範圍的樞紐分析表。你的工作是在週五之前更新 Q2 的數字。
你打開 Excel。儲存格有顏色標記,但沒有圖例。G 欄叫「Adj. Rev. (excl.)」,H 欄叫「Adj. Rev. (incl.)」 — 到底排除和包含的是什麼?第 47 列的公式引用了一個隱藏工作表裡的儲存格。另一個公式用 INDIRECT 從字串組合出儲存格參照,所以 Excel 的公式稽核追蹤功能什麼有用的資訊都顯示不了。
這不是資料問題,是理解問題。這份試算表是能運作的 — 大概吧。數字會跑出來,上一季也沒人抱怨。但你不理解它在做什麼,而改動你不理解的東西,就是在董事會報告前一週搞壞報表 pipeline 的最佳方法。
接手的試算表是一場考古挖掘。每一層是不同的人加上去的,帶著不同的假設,而且沒有人留下地圖。在 Excel 裡打開它,你看到的是出土文物。你真正需要的是一個翻譯 — 精通每一個版本的 Excel 的翻譯。
升級:AI Agent 當試算表翻譯
理解神秘試算表的標準做法:逐格點擊、一次追蹤一個公式的前置參照、在腦中建構資料流的心智模型。20 列的小表可以這樣做。14 個分頁、200 個公式的工作簿,不行。
Claude 的文件描述了兩個相關的使用案例:「理解並擴展接手的試算表」和「整理你的商業財務」。兩者都假設你把檔案上傳到聊天介面,等待回應,在瀏覽器視窗裡反覆來回。
終端做法更快也更強。不用上傳到 GUI,直接把試算表 pipe 進 AI CLI agent。Agent 一次讀取整個結構 — 每個工作表、每個公式、每個命名範圍 — 然後一趟就產出完整的工作簿地圖。不用點擊。不用切換分頁。不用「可以順便看一下 sheet 3 嗎?」
Workflow:
- 把試算表轉成可讀格式(如果需要的話)
- pipe 進 AI agent,搭配結構分析的 prompt
- 拿回完整地圖:工作表、欄位、用白話解釋的公式、工作表之間的依賴關係、標記出的錯誤
- 在同一個 session 裡追問
- 讓 agent 產出修正或更新後的版本
第一步:把試算表帶進終端
AI CLI agent 讀的是文字。.csv 本身就是文字 — 直接 pipe。.xlsx 需要先轉換。
CSV 檔案 — 不需要轉換:
cat quarterly_report.csv | claude -p "Map the structure of this spreadsheet. Explain every column, identify formulas or derived values, flag anything that looks like an error."
XLSX 檔案 — 用 Python 的 xlsx2csv 一行轉換:
pip install xlsx2csv
xlsx2csv -a quarterly_report.xlsx /tmp/sheets/
-a 旗標把所有工作表匯出成獨立的 CSV 檔案到目標目錄。現在你每個分頁一個 CSV:
/tmp/sheets/
Revenue.csv
Expenses.csv
Headcount.csv
Pivot_Summary.csv
...
全部餵給 agent:
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
cat "$f"
done | claude -p "This is a multi-sheet spreadsheet exported as CSV. Map the complete structure: what each sheet does, how they relate to each other, what formulas or derived columns exist, and flag any errors or inconsistencies."
Google Sheets — 從檔案選單匯出為 XLSX,然後用同樣的 xlsx2csv 轉換。或者直接把個別工作表匯出為 CSV。
第二步:結構分析 — 完整地圖
第一趟應該產出整個工作簿的結構地圖。以下 prompt 能穩定產出有用的輸出:
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
cat "$f"
done | claude -p "You are a spreadsheet auditor. Analyze this multi-sheet workbook and produce a structural report with these sections:
1. SHEET OVERVIEW — For each sheet: purpose, row count, column count, key columns
2. DATA FLOW — How sheets reference each other. Which sheet is the source of truth, which are derived
3. FORMULA AUDIT — Every formula or derived column, explained in plain English. Flag circular references, volatile functions (INDIRECT, OFFSET), and broken references
4. NAMED RANGES — Any named ranges or implicit ones (columns used as lookup keys)
5. ERROR FLAGS — Data type mismatches, hardcoded values that should be formulas, inconsistent formatting, missing data
6. DEPENDENCY GRAPH — A text-based diagram showing which sheets feed into which
Be specific. Cite cell references and exact values when flagging issues."
一個真實財務工作簿的典型輸出:
## SHEET OVERVIEW
### Revenue (Sheet 1)
- Purpose: Monthly revenue by product line
- Rows: 48 (12 months x 4 product lines)
- Key columns: Month, Product, Units, Unit_Price, Revenue
- Revenue column is derived: Units * Unit_Price
### Expenses (Sheet 2)
- Purpose: Monthly operating expenses by category
- Rows: 156 (12 months x 13 expense categories)
- Key columns: Month, Category, Budget, Actual, Variance
- Variance is derived: Budget - Actual
- WARNING: Rows 34-36 have hardcoded Variance values (42000, -15000, 8700)
instead of formulas. These will not update if Budget or Actual changes.
### Pivot_Summary (Sheet 4)
- Purpose: Executive summary aggregating Revenue and Expenses
- WARNING: References a column "Adj_Revenue" that does not appear in any
source sheet. The values appear to be manually entered.
最後那個警告 — 「Adj_Revenue 沒有出現在任何來源工作表」 — 手動找這個問題要 20 分鐘。Agent 幾秒就抓到,因為它一次讀完所有工作表,交叉比對所有欄位名稱。
第三步:用白話解釋公式
有了結構地圖,接下來深入特定公式。這是 agent 真正展現價值的地方。
cat /tmp/sheets/Revenue.csv | claude -p "This is the Revenue sheet of a financial workbook. For every column that contains derived or calculated values:
1. Explain what the formula does in plain English
2. Identify the inputs (which cells or columns it depends on)
3. Rate the formula: SOLID (correct and robust), FRAGILE (works but breaks easily), or BROKEN (produces wrong results)
4. For FRAGILE or BROKEN formulas, explain why and suggest a fix"
範例輸出:
## Column E: Revenue
- Formula: Units (C) * Unit_Price (D)
- Plain English: Multiplies units sold by price per unit to get total revenue
- Rating: SOLID — straightforward multiplication, no edge cases
## Column F: Growth_Pct
- Formula: (Current_Revenue - Previous_Revenue) / Previous_Revenue * 100
- Plain English: Percentage change in revenue from the previous month
- Rating: FRAGILE — Row 2 (January) has no previous month, so the formula
produces a division-by-zero error. Currently masked by an IFERROR wrapper
that returns 0, which is misleading (0% growth is different from "no data").
- Fix: Use IFERROR to return "N/A" or leave the cell blank for the first month.
## Column G: Adj_Revenue
- Formula: None detected — all values appear to be hardcoded
- Plain English: Unknown. Column header suggests "adjusted revenue" but there
is no formula showing what adjustment was applied.
- Rating: BROKEN — These values cannot be recalculated. If the source data
changes, this column will be stale. Likely a manual override from a previous
quarter that was never converted back to a formula.
- Fix: Determine the adjustment logic (tax? discount? FX conversion?) and
replace hardcoded values with a formula.
這才是價值所在。不是「這是你的數字」 — 而是「每個數字代表什麼意思、為什麼可能是錯的、怎麼修」。
第四步:錯誤偵測與資料品質檢查
除了公式稽核,agent 也能抓到 Excel 默默忽略的結構問題:
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
cat "$f"
done | claude -p "Audit this workbook for data quality issues. Check for:
1. Type mismatches — numbers stored as text, dates in inconsistent formats
2. Orphaned references — columns or sheets referenced nowhere
3. Duplicate rows or near-duplicates
4. Hardcoded values in cells that should contain formulas
5. Inconsistent naming — same entity spelled differently across sheets
6. Missing data — gaps in time series, incomplete rows
Output as a prioritized list: CRITICAL (will cause wrong results), WARNING (may cause confusion), INFO (cosmetic)."
Agent 在一個運作超過兩個季度的工作簿裡,通常能找到 5-15 個問題。最常見的:
- 臨時性的硬編碼覆蓋 — 本來是暫時的,結果變成永久的
- 日期格式不一致 — 一個工作表寫「March 2026」,另一個寫「2026-03」,第三個寫「3/1/26」
- 幽靈欄位 — 有標題但沒資料,或有資料但沒標題
- 複製貼上遺跡 — 某列被複製、修改了,但原始列沒有刪掉
第五步:產出更新版本
理解試算表是第一步。真正的任務通常是「更新 Q2 的數字」。Agent 也能做到。
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
cat "$f"
done | claude -p "This workbook contains Q1 actuals. I need to update it for Q2. Here are the Q2 numbers:
Product A: 1,240 units at \$102/unit
Product B: 890 units at \$205/unit
Product C: 445 units at \$89/unit
Product D: 2,100 units at \$47/unit
Update the Revenue sheet with these Q2 actuals. Recalculate all derived columns (Revenue, Growth_Pct). Fix the Adj_Revenue column by applying the same adjustment pattern visible in Q1 (if determinable) or flag it for manual input. Output the updated CSV."
Agent 讀取現有結構、理解公式的運作方式、插入新資料、重新計算衍生值,然後輸出乾淨的 CSV。如果有什麼無法判斷 — 比如那個謎之 Adj_Revenue 調整 — 它會明確告訴你,而不是瞎猜。
儲存輸出:
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
cat "$f"
done | claude -p "Update Revenue sheet with Q2 actuals: [numbers]. Output updated CSV only, no explanation." > /tmp/sheets/Revenue_Q2_updated.csv
用 CLAUDE.md 處理重複性試算表工作
如果你定期稽核試算表 — 每月財務結算、每季董事會報告、每週銷售對帳 — 把規則寫進 CLAUDE.md,讓每次 session 自動帶入脈絡:
# Spreadsheet Analysis Project
## Context
This directory contains quarterly financial workbooks exported from Google Sheets.
File naming: Q{quarter}_{year}_financial.xlsx (e.g., Q2_2026_financial.xlsx)
## Workbook Structure
- Revenue sheet: source of truth for sales data. Columns A-G.
- Expenses sheet: source of truth for opex. Columns A-F.
- Headcount sheet: FTE count by department. Updates quarterly.
- Pivot_Summary: executive summary — all values must be derived, never hardcoded.
## Known Issues
- Adj_Revenue in Revenue sheet is always hardcoded. Flag but do not attempt to fix.
- Expenses sheet uses "Marketing" and "Mktg" interchangeably — treat as same category.
- Growth_Pct formula in row 2 always shows 0% — this is the IFERROR fallback, not real data.
## Output Standards
- All monetary values in USD, no cents (round to nearest dollar)
- Dates as YYYY-MM format
- When generating updated CSVs, preserve the original column order exactly
- Flag any value that changed by more than 50% quarter-over-quarter
有了這個檔案,claude 在這個目錄裡的每次 session 都會自動載入這些規則。你不用再每次重複「記得 Adj_Revenue 是硬編碼的」。
分割終端 Workflow
試算表分析從同時看到資料和分析結果中獲益最大。最有效的配置:
左面板: Agent session。你 pipe 進試算表、提問、要求更新。Agent 串流輸出結構分析、公式解釋、錯誤報告。
右面板: 原始試算表資料,或用檢視器開啟的 CSV 檔案。當 agent 提到特定的儲存格、欄位或工作表,你可以立刻驗證,不需要切換視窗。
對更新的 workflow 來說,分割畫面更有用:
- 左面板:agent 產出更新後的 CSV
- 右面板:
diff原始與更新檔案,精確顯示每一處修改
diff /tmp/sheets/Revenue.csv /tmp/sheets/Revenue_Q2_updated.csv
你看到 agent 做的每一個修改。沒有隱藏的變動。不是「相信我,我更新好了」。每個差異都看得見。
處理大型或複雜工作簿
當工作簿超過 context window — 數十萬行、幾十個工作表 — 用分階段的方式:
第一階段:只看標題。 只擷取每個工作表的欄位標題,不把 token 花在資料上,先取得結構概覽:
for f in /tmp/sheets/*.csv; do
echo "=== Sheet: $(basename "$f" .csv) ==="
head -1 "$f"
done | claude -p "These are the column headers from each sheet of a workbook. Map the structure: what each sheet likely does, how they probably relate, which columns are likely derived. Identify which sheets I should analyze in detail first."
第二階段:優先工作表。 根據 agent 的建議,完整分析最重要的工作表:
cat /tmp/sheets/Revenue.csv | claude -p "Full analysis of this Revenue sheet. Map every column, explain derived values, flag errors."
第三階段:跨工作表驗證。 個別工作表理解後,驗證它們之間的關聯:
cat /tmp/sheets/Revenue.csv /tmp/sheets/Pivot_Summary.csv | claude -p "These two sheets should be linked: Pivot_Summary should aggregate Revenue. Verify: are the summary values consistent with the detail? Flag any discrepancy."
這個分階段做法讓每個 prompt 保持聚焦、控制在 token limit 內,同時仍然產出完整的工作簿分析。
什麼時候該用(什麼時候不該用)
適合用 AI CLI 分析試算表的場景:
- 接手的工作簿,需要先理解結構再做任何修改
- 公式稽核 — 抓出壞掉的參照、硬編碼覆蓋、循環參照
- 月結或季結前的資料品質檢查
- 把「神秘試算表」轉化成有文件記錄、可維護的邏輯
- 快速更新 — 你理解結構,但想讓 agent 處理機械性的工作
繼續用 Excel 或 Google Sheets 的場景:
- 需要互動式樞紐分析表或搭配交叉篩選器的圖表
- 工作簿使用 VBA 巨集(agent 可以讀取但無法執行)
- 需要和非技術利害關係人即時協作
- 任務純粹是視覺性的 — 條件格式化、版面調整
最佳命中區域是理解。當問題是「我不理解這份試算表在做什麼」,AI agent 一次讀完整個結構的速度,比任何程度的逐格點擊都快。當問題是「我要做一張圖給董事會簡報」,用 GUI。
重點整理
接手的試算表不是資料問題 — 是理解問題。AI CLI agent 的解法是一次讀完整個結構,翻譯成你能據以行動的語言。
核心 workflow:
- 轉換 —
xlsx2csv -a把所有工作表匯出為 CSV - 對應 — pipe 進 agent 做完整結構分析
- 解釋 — 深入特定公式取得白話解說
- 稽核 — 標記錯誤、硬編碼值、壞掉的參照
- 更新 — 用新資料產出修正後的 CSV
- 差異比對 — 用
diff驗證每一個修改,再替換原始檔案
不需要 Excel。不需要 GUI。試算表進你的終端,agent 幫你翻譯。
Ready to streamline your terminal workflow?
Multi-terminal drag-and-drop layout, workspace Git sync, built-in AI integration, AST code analysis — all in one app.