mcpField
X
xlsx

xlsx

github.com/stvlynnドキュメント12196 回インストール32 週間前に更新
リポジトリ

xlsx について

xlsxは、データ分析、レポート作成、財務モデリング、複数ファイルの処理に対応するExcel向けスキルです。数式の再計算と出力検証を手順に含み、数式エラーのないファイルを作成する方針です。

主な機能

  1. 01表データの分析とクリーニング
  2. 02レポートの自動生成
  3. 03数式を含む表計算ファイルの作成
  4. 04Excelファイルの一括処理
  5. 05数式の再計算とエラー確認
  6. 06既存テンプレートの書式維持

活用シーン

  1. 01データを集計して統計レポートを作成
  2. 02数式付きの売上レポートを作成
  3. 03色分けした財務予測モデルを構築
  4. 04複数のExcelファイルを整理・統合

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/stvlynn/dingtalk-wukong-skills --skill xlsx

インストール後、Claude Code で/xlsxを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

requirements.txt
docs/
00-SKILL-完整操作指南.md
scripts/
recalc.py

詳細

Excelスプレッドシート処理のエキスパート Real Skill

一言で説明

ゼロの数式エラーを必須基準とする、データ分析、レポート生成、財務モデリングに対応したプロフェッショナルな Excel 処理ツールです。

Excel Spreadsheet Mastery - 数式エラーゼロの基準、データ分析、自動レポート生成、色分けによる財務モデリング。


使用シーン

適しています:

  • データ分析と統計レポート
  • Excel レポートの自動生成
  • 財務予測モデル(色分け)
  • 複数の Excel ファイルの一括処理
  • データのクレンジングと形式変換

適していません:

  • リアルタイムの共同編集(Google Sheets を使用)
  • 複雑なマクロ操作(複雑なマクロには VBA を使用)

コアワークフロー

用户需求 → 判断任务类型 → 选择工具 → 执行操作 → 公式重算 → 验证输出
User request → Task classification → Tool selection → Execute → Recalc formulas → Validate

タスクの種類の判定 (Task Classification):

データ分析 (Data Analysis)
  • シンプルな分析 → pandas(読み込み、分析、可視化)
  • 統計レポート → pandas + matplotlib/seaborn
  • データのクレンジング → pandas による変換
スプレッドシートの作成 (Spreadsheet Creation)
  • 数式あり → openpyxl + recalc.py(必須)
  • 数式なし → pandas(より高速)
  • 財務モデル → openpyxl + 色分け + recalc.py
既存ファイルの編集 (Editing Existing)
  • データの更新 → openpyxl(数式を保持)
  • テンプレートの変更 → 既存の書式に完全に合わせます

⚠️ 重要:数式を使用した後は、必ず python scripts/recalc.py output.xlsx を実行してください。


タスクの完了基準

すべて満たす必要があります(1つでも欠けてはなりません):

  • ✅ 数式エラーゼロ (Zero Formula Errors)(#REF!、#DIV/0!、#VALUE!、#N/A、#NAME? = 0)
  • Excel ファイルを正常に開けること
  • データが完全かつ正確であること
  • 書式が適切であること(数値形式、配置、罫線)
  • 該当する場合、財務モデルで業界標準の色分けを使用していること

品質評価:

  • ⭐⭐⭐⭐⭐ 優秀 - エラーゼロ + 色分け + 完全なドキュメント
  • ⭐⭐⭐ 合格 - エラーゼロ + データが正確
  • ⭐ 失敗 - 数式エラーあり

参考資料(AI 向け)

種類パス説明
コアドキュメントdocs/00-SKILL-完整操作指南.mdExcel 処理の完全ガイド(約300行)
ツールスクリプトscripts/recalc.py数式の再計算スクリプト(LibreOffice が必要)

重要な原則(AI は必ず読むこと / Critical Principles)

1. ⚠️ 数式エラーゼロの原則 (Zero Formula Errors - 必須)

すべての Excel ファイルは、数式エラーがゼロの状態で必ず納品してください:

  • #REF! を含めない(無効な参照)
  • #DIV/0! を含めない(ゼロ除算)
  • #VALUE! を含めない(データ型の誤り)
  • #N/A を含めない(検索対象が見つからない)
  • #NAME? を含めない(認識されない数式名)

検証ワークフロー:

python scripts/recalc.py output.xlsx
# Check JSON output: status should be "success"
# If "errors_found", fix and recalculate
2. ハードコードされた値ではなく数式を使用

重要:Python で計算するのではなく、常に Excel の数式を使用してください。

❌ 誤り - ハードコード:

total = df['Sales'].sum()
sheet['B10'] = total  # Hardcodes 5000

✅ 正しい - 数式を使用:

sheet['B10'] = '=SUM(B2:B9)'  # Dynamic formula

理由:元データが変更されても、スプレッドシートを動的に更新できる状態に保てます。

3. 財務モデリングの色分け

業界標準の色の使い分け(ユーザーから別途指定がない場合):

from openpyxl.styles import Font

# Blue text (0000FF): User inputs and assumptions
ws['A1'].font = Font(color='0000FF')

# Black text (000000): ALL formulas and calculations
ws['B1'].font = Font(color='000000')

# Green text (008000): Links within same workbook
ws['C1'].font = Font(color='008000')

# Red text (FF0000): External file links
ws['D1'].font = Font(color='FF0000')

# Yellow background (FFFF00): Key assumptions
from openpyxl.styles import PatternFill
ws['E1'].fill = PatternFill(start_color='FFFF00', fill_type='solid')
4. 数値形式の基準
from openpyxl.styles import numbers

# Years: Format as text strings "2024" (not numbers)
ws['A1'].number_format = '@'  # Text format
ws['A1'] = "'2024"  # Force text

# Currency: $#,##0 + specify units in header
ws['B1'].number_format = '$#,##0'

# Zeros: Format as "-"
ws['C1'].number_format = '$#,##0;($#,##0);"-"'

# Percentages: 0.0% (one decimal)
ws['D1'].number_format = '0.0%'

# Multiples: 0.0x for valuation multiples
ws['E1'].number_format = '0.0"x"'

# Negative numbers: Use parentheses (123) not minus -123
ws['F1'].number_format = '#,##0;(#,##0)'
5. 既存のテンプレートを維持

既存ファイルを変更する場合:

  • 既存の書式、スタイル、規則を確認し、完全に合わせます
  • 確立されたパターンがあるファイルに、標準書式を押し付けないでください
  • 既存のテンプレートの規則は、常にこのガイドラインより優先されます

クイックコマンドリファレンス (Quick Commands)

Pandas によるデータ分析
import pandas as pd

# Read Excel (single sheet or all)
df = pd.read_excel('file.xlsx')  # First sheet
all_sheets = pd.read_excel('file.xlsx', sheet_name=None)  # All sheets as dict

# Analyze
df.head()       # Preview data
df.info()       # Column info
df.describe()   # Statistics
df.groupby('Category')['Sales'].sum()  # Group by

# Write Excel
df.to_excel('output.xlsx', index=False)
数式付き Excel の作成
from openpyxl import Workbook
from openpyxl.styles import Font

wb = Workbook()
ws = wb.active

# Data with formulas
ws['A1'] = 'Revenue'
ws['A2'] = 1000
ws['A3'] = 1200
ws['A4'] = 'Total'
ws['B4'] = '=SUM(A2:A3)'  # Use formula, not hardcoded value

# Color coding
ws['A2'].font = Font(color='0000FF')  # Blue: User input
ws['B4'].font = Font(color='000000')  # Black: Formula

wb.save('output.xlsx')
数式の再計算(必須)
# After saving file with formulas
python scripts/recalc.py output.xlsx

# Output JSON shows:
# - status: "success" or "errors_found"
# - error_summary: Details of any errors
# - total_errors: Count of formula errors
色分けによる財務モデリング
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill

wb = Workbook()
ws = wb.active

# Headers
ws['A1'] = 'Year'
ws['B1'] = 'Revenue ($mm)'
ws['C1'] = 'Growth %'

# Data with color coding
ws['A2'] = "'2024"  # Force text for year
ws['B2'] = 100
ws['B2'].font = Font(color='0000FF')  # Blue: User input

ws['C2'] = 0.15  # Growth assumption
ws['C2'].font = Font(color='0000FF')
ws['C2'].fill = PatternFill(start_color='FFFF00', fill_type='solid')  # Yellow: Key assumption
ws['C2'].number_format = '0.0%'

# Formulas
ws['B3'] = '=B2*(1+C2)'  # Revenue calculation
ws['B3'].font = Font(color='000000')  # Black: Formula

wb.save('financial_model.xlsx')

# MUST recalculate
import subprocess
subprocess.run(['python', 'scripts/recalc.py', 'financial_model.xlsx'])
エラー処理
import subprocess
import json

# Run recalc and check results
result = subprocess.run(
    ['python', 'scripts/recalc.py', 'output.xlsx'],
    capture_output=True,
    text=True
)

data = json.loads(result.stdout)

if data['status'] == 'errors_found':
    print(f"Found {data['total_errors']} errors:")
    for error_type, count in data['error_summary'].items():
        print(f"  {error_type}: {count}")
    # Fix errors and recalculate
else:
    print("✅ Zero formula errors - file ready!")

依存関係のインストール

Python の依存関係
pip install -r requirements.txt
# Includes: openpyxl, pandas, xlrd, openpyxl
システム依存関係 (LibreOffice)
# macOS
brew install --cask libreoffice

# Ubuntu/Debian
sudo apt-get install libreoffice

# Windows: Download from https://www.libreoffice.org/

注:recalc.py は初回実行時に LibreOffice を自動的に設定します。


よくあるシーンの例

シナリオ 1:自動合計付きの売上レポートを作成
import pandas as pd
from openpyxl import load_workbook
from openpyxl.styles import Font

# Step 1: Create data with pandas
data = {
    'Product': ['A', 'B', 'C'],
    'Q1': [1000, 800, 1200],
    'Q2': [1100, 850, 1300],
    'Q3': [1050, 900, 1250],
    'Q4': [1200, 950, 1400]
}
df = pd.DataFrame(data)
df.to_excel('sales.xlsx', index=False, startrow=1)

# Step 2: Add formulas with openpyxl
wb = load_workbook('sales.xlsx')
ws = wb.active

# Add title
ws['A1'] = '2024 Sales Report ($000s)'
ws['A1'].font = Font(bold=True, size=14)

# Add totals row
last_row = len(df) + 2
ws[f'A{last_row}'] = 'Total'
ws[f'A{last_row}'].font = Font(bold=True)

for col in ['B', 'C', 'D', 'E']:
    ws[f'{col}{last_row}'] = f'=SUM({col}2:{col}{last_row-1})'
    ws[f'{col}{last_row}'].font = Font(color='000000', bold=True)

wb.save('sales.xlsx')

# Step 3: Recalculate
import subprocess
subprocess.run(['python', 'scripts/recalc.py', 'sales.xlsx'])
シナリオ 2:3年間の財務予測
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment

wb = Workbook()
ws = wb.active

# Headers
headers = ['Metric', '2024', '2025', '2026']
for col, header in enumerate(headers, start=1):
    ws.cell(1, col, header)
    ws.cell(1, col).font = Font(bold=True)
    ws.cell(1, col).alignment = Alignment(horizontal='center')

# Assumptions (Blue + Yellow background)
ws['A2'] = 'Base Revenue'
ws['B2'] = 10000
ws['B2'].font = Font(color='0000FF')
ws['B2'].fill = PatternFill(start_color='FFFF00', fill_type='solid')

ws['A3'] = 'Growth Rate'
ws['B3'] = 0.15
ws['B3'].font = Font(color='0000FF')
ws['B3'].fill = PatternFill(start_color='FFFF00', fill_type='solid')
ws['B3'].number_format = '0.0%'

# Calculations (Black formulas)
ws['A5'] = 'Projected Revenue'
ws['B5'] = '=B2'
ws['B5'].font = Font(color='000000')

ws['C5'] = '=B5*(1+$B$3)'
ws['C5'].font = Font(color='000000')

ws['D5'] = '=C5*(1+$B$3)'
ws['D5'].font = Font(color='000000')

# Number formatting
for col in ['B', 'C', 'D']:
    ws[f'{col}5'].number_format = '$#,##0'

wb.save('projection.xlsx')

# MUST recalculate
import subprocess
subprocess.run(['python', 'scripts/recalc.py', 'projection.xlsx'])
シナリオ 3:複数の Excel ファイルを一括処理
import pandas as pd
import glob

all_data = []

for file in glob.glob('data/*.xlsx'):
    df = pd.read_excel(file)
    df['source_file'] = file
    all_data.append(df)

combined = pd.concat(all_data, ignore_index=True)
combined.to_excel('combined_report.xlsx', index=False)

print(f"Processed {len(all_data)} files, total {len(combined)} rows")

コメント