i18n/zh-TW/xlsx/SKILL.md
當試算表檔案是主要的輸入或輸出時,使用此技能。涵蓋以下任務:開啟、讀取、編輯或修復現有的 .xlsx、.xlsm、.csv 或 .tsv 檔案(例如新增欄位、計算公式、套用格式、製作圖表、清理雜亂資料);從零或從其他資料來源建立新的試算表;或在不同表格檔案格式之間轉換。當使用者以檔名或路徑提及試算表(即使只是隨口提到「我下載夾裡那個 xlsx」)並希望對它做點什麼或從中產出結果時,特別應觸發此技能;將格式錯亂的表格資料(行列錯位、表頭擺錯、夾雜雜訊)整理成正規試算表的需求也適用。最終交付物必須是試算表檔案。若主要交付物是 Word 文件、HTML 報告、獨立 Python 腳本、資料庫管線,或 Google Sheets API 整合(即使過程涉及表格資料),請勿觸發此技能。
npx skillsauth add tai-ch0802/skills-bundle xlsxInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
除非使用者或現有範本另有說明:
$#,##0 格式;務必在標題中指定單位(如 "營收 ($mm)")。"$#,##0;($#,##0);-")。=B5*(1+$B$6) 而不是 =B5*1.05。使用者可能會要求你建立、編輯或分析 .xlsx 檔案的內容。針對不同的任務,你有不同的工具與工作流程可供使用。
重新計算公式需要 LibreOffice:你可以假設已安裝 LibreOffice,並使用 scripts/recalc.py 腳本來重新計算公式值。該腳本會在首次執行時自動配置 LibreOffice,包括在 Unix sockets 受到限制的沙盒環境中(由 scripts/office/soffice.py 處理)。
對於資料分析、視覺化與基本操作,請使用提供強大資料操作功能的 pandas:
import pandas as pd
# 讀取 Excel
df = pd.read_excel('file.xlsx') # 預設:第一個工作表
all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # 所有工作表以 dict 呈現
# 分析
df.head() # 預覽資料
df.info() # 欄位資訊
df.describe() # 統計數據
# 寫入 Excel
df.to_excel('output.xlsx', index=False)
請一律使用 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 計算總和
sheet['B10'] = '=SUM(B2:B9)'
# 良好示範:成長率作為 Excel 公式
sheet['C5'] = '=(C4-C2)/C2'
# 良好示範:使用 Excel 公式計算平均數
sheet['D20'] = '=AVERAGE(D2:D19)'
此原則適用於所有計算 — 總計、百分比、比率、差值等等。當來源資料改變時,試算表必須能夠重新計算。
scripts/recalc.py 腳本
python scripts/recalc.py output.xlsx
status 為 errors_found,請查看 error_summary 以瞭解錯誤類型與位置#REF!:無效的儲存格參照#DIV/0!:除以零#VALUE!:公式中的資料型別錯誤#NAME?:無法識別的公式名稱# 使用 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')
# 使用 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 檔案會以字串形式保留公式,但不包含計算後的數值。請使用內附的 scripts/recalc.py 腳本重新計算公式:
python scripts/recalc.py <excel_file> [timeout_seconds]
範例:
python scripts/recalc.py output.xlsx 30
此腳本會:
確保公式正確運作的快速檢查項目:
pd.notna() 檢查空值。/ 之前先檢查分母(#DIV/0!)。Sheet1!A1)連結不同工作表。scripts/recalc.py 的輸出腳本會回傳含錯誤資訊的 JSON:
{
"status": "success", // 或 "errors_found"
"total_errors": 0, // 錯誤總數
"total_formulas": 42, // 檔案內公式數量
"error_summary": { // 僅在發現錯誤時出現
"#REF!": {
"count": 2,
"locations": ["Sheet1!B5", "Sheet1!C10"]
}
}
}
data_only=True 讀取計算後的數值:load_workbook('file.xlsx', data_only=True)。data_only=True 開啟後再存檔,公式會被替換成數值並永久遺失。read_only=True;寫入時使用 write_only=True。scripts/recalc.py 更新計算結果。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 程式碼時:
print 敘述。對 Excel 檔案本身:
development
Unified testing skill — TDD workflow, unit/integration patterns, E2E/Playwright strategies. Replaces tdd-workflow + testing-patterns + webapp-testing.
testing
Security-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
development
Spec-Driven Development (SDD): A structured workflow (Requirement -> Analysis -> Implementation) enforcing explicit documentation before coding.
development
Methodologies for System Analysis (SA), focusing on technical architecture, data flow modeling, and API design.