全面的电子表格创建、编辑和分析功能,支持公式、格式化、数据分析和可视化。当 Claude 需要处理电子表格(.xlsx、.xlsm、.csv、.tsv 等)时使用,包括:(1) 创建带有公式和格式的新电子表格,(2) 读取或分析数据,(3) 修改现有电子表格同时保留公式,(4) 电子表格中的数据分析和可视化,或 (5) 重新计算公式
npx skills add https://github.com/LeastBit/Claude_skills_zh-CN --skill xlsx
除非用户或现有模板另有说明
用户可能要求您创建、编辑或分析 .xlsx 文件的内容。您有不同的工具和工作流程可用于不同的任务。
公式重新计算需要 LibreOffice:可以假设已安装 LibreOffice 用于通过 recalc.py 脚本重新计算公式值。该脚本在首次运行时会自动配置 LibreOffice
对于数据分析、可视化和基本操作,使用 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 公式,而不是在 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)'
这适用于所有计算 - 合计、百分比、比率、差值等。电子表格应该能够在源数据更改时重新计算。
python 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_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文件> [超时秒数]
示例:
python recalc.py output.xlsx 30
该脚本:
确保公式正常工作的快速检查:
pd.notna() 检查空值/ 之前检查分母(#DIV/0!)脚本返回包含错误详情的 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=Truepd.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 代码时:
对于 Excel 文件本身:
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \"the xlsx in my downloads\") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.
Picks random winners from lists, spreadsheets, or Google Sheets for giveaways, raffles, and contests. Ensures fair, unbiased selection with transparency.
Query openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), substance identification (UNII), for FDA regulatory data analysis and safety research.
MATLAB and GNU Octave numerical computing for matrix operations, data analysis, visualization, and scientific computing. Use when writing MATLAB/Octave scripts for linear algebra, signal processing, image processing, differential equations, optimization, statistics, or creating scientific visualizations. Also use when the user needs help with MATLAB syntax, functions, or wants to convert between MATLAB and Python code. Scripts can be executed with MATLAB or the open-source GNU Octave interpreter.
UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.
Creating interactive data visualisations using d3.js. This skill should be used when creating custom charts, graphs, network diagrams, geographic visualisations, or any complex SVG-based data visualisation that requires fine-grained control over visual elements, transitions, or interactions. Use this for bespoke visualisations beyond standard charting libraries, whether in React, Vue, Svelte, vanilla JavaScript, or any other environment.
Access AlphaFold 200M+ AI-predicted protein structures. Retrieve structures by UniProt ID, download PDB/mmCIF files, analyze confidence metrics (pLDDT, PAE), for drug discovery and structural biology.
Take leastbit/xlsx from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.