Community程式設計與開發github.com

xlsx

全面的試算表建立、編輯與分析功能,支援公式、格式化、資料分析與視覺化。當 Claude 需要處理 .xlsx、.xlsm、.csv、.tsv 等試算表檔案時使用。

xlsx 是什麼?

這個技能為 AI 助手提供完整的試算表操作能力,包括建立、編輯與分析 Excel (.xlsx) 等格式的檔案。它特別強調使用 Excel 公式而非在 Python 中硬編碼計算結果,以保持試算表的動態性與可更新性。支援的平臺包含 Claude Code 及任何可執行 Python 與 openpyxl/pandas 的環境。技能透過 openpyxl 處理公式與格式化,並提供 recalc.py 指令碼(依賴 LibreOffice)來重新計算公式值並驗證錯誤。此外,它強制執行金融模型的色彩編碼與數字格式標準,確保輸出符合業界慣例,並在更新時精確保留既有範本的格式。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComposioHQ/awesome-claude-skills/tree/master/document-skills/xlsx

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

產出要求

所有 Excel 檔案

零公式錯誤

  • 每個 Excel 模型都必須以零公式錯誤 (#REF!、#DIV/0!、#VALUE!、#N/A、#NAME?) 交付

保留既有範本(更新範本時)

  • 修改檔案時,須研究並完全比對既有格式、樣式與慣例
  • 不得對已建立模式的檔案強加標準化格式
  • 既有範本慣例一律優先於本指南

財務模型

色彩編碼標準

除非使用者或既有範本另有指定

業界標準色彩慣例

  • 藍色文字 (RGB: 0,0,255):硬編碼的輸入值,以及使用者將為不同情境更改的數字
  • 黑色文字 (RGB: 0,0,0):所有公式與計算
  • 綠色文字 (RGB: 0,128,0):從同一個活頁簿的其他工作表連結過來的資料
  • 紅色文字 (RGB: 255,0,0):連到其他檔案的外部連結
  • 黃色背景 (RGB: 255,255,0):需要注意的關鍵假設或需要更新的儲存格

數字格式標準

必要格式規則

  • 年份:格式為文字字串(例如 "2024" 而非 "2,024")
  • 貨幣:使用 $#,##0 格式;務必在標題中指定單位("營收 ($mm)")
  • 零值:使用數字格式將所有零顯示為 "-",包括百分比(例如 "$#,##0;($#,##0);-")
  • 百分比:預設為 0.0% 格式(小數一位)
  • 倍數:估值倍數(EV/EBITDA、P/E)格式化為 0.0x
  • 負數:使用括號 (123) 而非負號 -123

公式建構規則

假設放置

  • 將所有假設(成長率、邊際利潤、倍數等)放在獨立的假設儲存格中
  • 在公式中使用儲存格參照而非硬編碼值
  • 範例:使用 =B5*(1+$B$6) 而非 =B5*1.05

公式錯誤預防

  • 驗證所有儲存格參照是否正確
  • 檢查範圍是否有差一錯誤
  • 確保所有預測期間的公式一致
  • 以邊界情況(零值、負數)測試
  • 確認無非預期的循環參照

硬編碼值文件要求

  • 在儲存格旁(若為表格結尾)加上註解。格式:「來源:[系統/文件],[日期],[特定參考],[網址(若適用)」
  • 範例:
    • 「來源:Company 10-K, FY2024, 第45頁, 營收附註, [SEC EDGAR 網址]」
    • 「來源:Company 10-Q, Q2 2025, Exhibit 99.1, [SEC EDGAR 網址]」
    • 「來源:Bloomberg Terminal, 8/15/2025, AAPL US Equity」
    • 「來源:FactSet, 8/20/2025, 共識預測畫面」

XLSX 建立、編輯與分析

概覽

使用者可能要求您建立、編輯或分析 .xlsx 檔案的內容。針對不同任務,您有不同的工具與工作流程可用。

重要要求

LibreOffice 為公式重新計算所必需:您可以假設已安裝 LibreOffice,用於透過 recalc.py 指令碼重新計算公式值。該指令碼在首次執行時會自動設定 LibreOffice

讀取與分析資料

使用 pandas 進行資料分析

對於資料分析、視覺化與基本操作,請使用 pandas,它提供強大的資料處理能力:

import pandas as pd

# 讀取 Excel
df = pd.read_excel('file.xlsx')  # 預設:第一個工作表
all_sheets = pd.read_excel('file.xlsx', sheet_name=None)  # 所有工作表,以字典形式

# 分析
df.head()      # 預覽資料
df.info()      # 欄位資訊
df.describe()  # 統計摘要

# 寫入 Excel
df.to_excel('output.xlsx', index=False)

Excel 檔案工作流程

關鍵:使用公式,而非硬編碼值

一律使用 Excel 公式,而非在 Python 中計算數值再硬編碼。 這能確保試算表保持動態且可更新。

❌ 錯誤做法 - 硬編碼計算結果

# 不好:在 Python 中計算並硬編碼結果
total = df['Sales'].sum()
sheet['B10'] = total  # 硬編碼 5000

# 不好:在 Python 中計算成長率
growth = (df.iloc[-1]['Revenue'] - df.iloc[0]['Revenue']) / df.iloc[0]['Revenue']
sheet['C5'] = growth  # 硬編碼 0.15

# 不好:Python 計算平均值
avg = sum(values) / len(values)
sheet['D20'] = avg  # 硬編碼 42.5

✅ 正確做法 - 使用 Excel 公式

# 好:讓 Excel 計算總和
sheet['B10'] = '=SUM(B2:B9)'

# 好:成長率以 Excel 公式表示
sheet['C5'] = '=(C4-C2)/C2'

# 好:使用 Excel 函數計算平均值
sheet['D20'] = '=AVERAGE(D2:D19)'

這適用於所有計算——總計、百分比、比率、差異等。試算表應能在來源資料變更時重新計算。

常見工作流程

  1. 選擇工具:資料分析用 pandas,公式/格式化用 openpyxl
  2. 建立/載入:建立新活頁簿或載入既有檔案
  3. 修改:新增/編輯資料、公式與格式化
  4. 儲存:寫入檔案
  5. 重新計算公式(若使用公式則為強制步驟):使用 recalc.py 指令碼
    python recalc.py output.xlsx
    
  6. 驗證並修正任何錯誤:
    • 該指令碼會傳回包含錯誤詳細資訊的 JSON
    • 若 status 為 errors_found,請檢查 error_summary 以了解特定錯誤類型與位置
    • 修正已識別的錯誤後再次重新計算
    • 常見需修正的錯誤:
      • #REF!:無效的儲存格參照
      • #DIV/0!:除以零
      • #VALUE!:公式中的資料型別錯誤
      • #NAME?:無法辨識的公式名稱

建立新的 Excel 檔案

# 使用 openpyxl 處理公式與格式化
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment

wb = Workbook()
sheet = wb.active

# 新增資料
sheet['A1'] = 'Hello'
sheet['B1'] = 'World'
sheet.append(['Row', 'of', 'data'])

# 新增公式
sheet['B2'] = '=SUM(A1:A10)'

# 格式化
sheet['A1'].font = Font(bold=True, color='FF0000')
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')

# 欄寬
sheet.column_dimensions['A'].width = 20

wb.save('output.xlsx')

編輯既有的 Excel 檔案

# 使用 openpyxl 保留公式與格式化
from openpyxl import load_workbook

# 載入既有檔案
wb = load_workbook('existing.xlsx')
sheet = wb.active  # 或 wb['SheetName'] 指定特定工作表

# 處理多個工作表
for sheet_name in wb.sheetnames:
    sheet = wb[sheet_name]
    print(f"Sheet: {sheet_name}")

# 修改儲存格
sheet['A1'] = 'New Value'
sheet.insert_rows(2)  # 在第 2 列插入列
sheet.delete_cols(3)  # 刪除第 3 欄

# 新增工作表
new_sheet = wb.create_sheet('NewSheet')
new_sheet['A1'] = 'Data'

wb.save('modified.xlsx')

重新計算公式

由 openpyxl 建立或修改的 Excel 檔案包含公式字串,但未包含計算後的值。請使用提供的 recalc.py 指令碼重新計算公式:

python recalc.py <excel_file> [timeout_seconds]

範例:

python recalc.py output.xlsx 30

此指令碼:

  • 首次執行時自動設定 LibreOffice 巨集
  • 重新計算所有工作表中的所有公式
  • 掃描所有儲存格是否有 Excel 錯誤 (#REF!、#DIV/0! 等)
  • 傳回包含詳細錯誤位置與計數的 JSON
  • 可同時在 Linux 與 macOS 上運作

公式驗證檢查清單

確保公式正確運作的快速檢查:

必要驗證

  • 測試 2-3 個樣本參照:在建立完整模型前,確認它們能提取正確的值
  • 欄位對應:確認 Excel 欄位對應正確(例如第 64 欄是 BL,不是 BK)
  • 列偏移:記住 Excel 列是從 1 開始索引(DataFrame 第 5 列 = Excel 第 6 列)

常見陷阱

  • NaN 處理:使用 pd.notna() 檢查空值
  • 極右欄位:FY 資料常在第 50 欄之後
  • 多個相符:搜尋所有出現處,而非僅第一個
  • 除以零:在公式中使用 / 前檢查分母(#DIV/0!)
  • 錯誤參照:驗證所有儲存格參照是否指向預期儲存格(#REF!)
  • 跨工作表參照:使用正確格式 (Sheet1!A1) 來連結工作表

公式測試策略

  • 從小處著手:先對 2-3 個儲存格測試公式,再廣泛應用
  • 驗證相依性:檢查公式中參照的所有儲存格是否存在
  • 測試邊界情況:包含零、負數與非常大的數值

解讀 recalc.py 的輸出

該指令碼傳回包含錯誤詳細資訊的 JSON:

{
  "status": "success",           // 或 "errors_found"
  "total_errors": 0,              // 錯誤總數
  "total_formulas": 42,           // 檔案中的公式數量
  "error_summary": {              // 僅在發現錯誤時出現
    "#REF!": {
      "count": 2,
      "locations": ["Sheet1!B5", "Sheet1!C10"]
    }
  }
}

最佳做法

函式庫選擇

  • pandas:最適合資料分析、批次操作與簡單資料匯出
  • openpyxl:最適合複雜格式化、公式與 Excel 專屬功能

使用 openpyxl

  • 儲存格索引由 1 開始(row=1, column=1 代表儲存格 A1)
  • 使用 data_only=True 讀取計算後的值:load_workbook('file.xlsx', data_only=True)
  • 警告:若以 data_only=True 開啟並儲存,公式將被值取代且永久遺失
  • 對於大型檔案:讀取時使用 read_only=True,寫入時使用 write_only=True
  • 公式會被保留但不會被計算——請使用 recalc.py 更新數值

使用 pandas

  • 指定資料型別以避免推斷問題:pd.read_excel('file.xlsx', dtype={'id': str})
  • 對於大型檔案,讀取特定欄位:pd.read_excel('file.xlsx', usecols=['A', 'C', 'E'])
  • 正確處理日期:pd.read_excel('file.xlsx', parse_dates=['date_column'])

程式碼風格指南

重要:在產生用於 Excel 操作的 Python 程式碼時:

  • 撰寫簡潔、不必要註解的 Python 程式碼
  • 避免冗長的變數名稱與多餘操作
  • 避免不必要的 print 陳述式

對於 Excel 檔案本身:

  • 在包含複雜公式或重要假設的儲存格中加入註解
  • 記錄硬編碼值的資料來源
  • 為關鍵計算與模型區塊加入備註

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ably-automation

Automate Ably tasks via Rube MCP (Composio). Always search tools first for current schemas.

abstract-automation

Automate Abstract tasks via Rube MCP (Composio). Always search tools first for current schemas.

abuselpdb-automation

Automate Abuselpdb tasks via Rube MCP (Composio). Always search tools first for current schemas.

abyssale-automation

Automate Abyssale tasks via Rube MCP (Composio). Always search tools first for current schemas.

accelo-automation

Automate Accelo tasks via Rube MCP (Composio). Always search tools first for current schemas.

accredible-certificates-automation

Automate Accredible Certificates tasks via Rube MCP (Composio). Always search tools first for current schemas.

acculynx-automation

Automate Acculynx tasks via Rube MCP (Composio). Always search tools first for current schemas.

active-campaign-automation

Automate ActiveCampaign tasks via Rube MCP (Composio). Always search tools first for current schemas.

addresszen-automation

Automate Addresszen tasks via Rube MCP (Composio). Always search tools first for current schemas.

adobe-automation

Automate Adobe tasks via Rube MCP (Composio). Always search tools first for current schemas.

adrapid-automation

Automate Adrapid tasks via Rube MCP (Composio). Always search tools first for current schemas.

adyntel-automation

Automate Adyntel tasks via Rube MCP (Composio). Always search tools first for current schemas.

aeroleads-automation

Automate Aeroleads tasks via Rube MCP (Composio). Always search tools first for current schemas.

aero-workflow-automation

Automate Aero Workflow tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinda-automation

Automate Affinda tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinity-automation

Automate Affinity tasks via Rube MCP (Composio). Always search tools first for current schemas.

agencyzoom-automation

Automate Agencyzoom tasks via Rube MCP (Composio). Always search tools first for current schemas.

agent-mail-automation

Automate Agent Mail tasks via Rube MCP (Composio). Always search tools first for current schemas.

agentql-automation

Automate Agentql tasks via Rube MCP (Composio). Always search tools first for current schemas.

agenty-automation

Automate Agenty tasks via Rube MCP (Composio). Always search tools first for current schemas.

相關技能