科研效率
未发现用户侧风险
电子表格技能
当任务涉及创建、编辑、分析或格式化电子表格(`.xlsx`、`.csv`、`.tsv`)时使用,特别是当需要保留和验证公式、引用和格式时,通过 Python(`openpyxl`、`pandas`)来实现。
文件预览
9 个文件
agents
assets
references
examples
openpyxl
SKILL.md
5.1 KB · 可预览
--- name: "spreadsheet" description: "Use when tasks involve creating, editing, analyzing, or formatting spreadsheets (`.xlsx`, `.csv`, `.tsv`) using Python (`openpyxl`, `pandas`), especially when formulas, references, and formatting need to be preserved and verified." author: openai --- # Spreadsheet Skill (Create, Edit, Analyze, Visualize) ## When to use - Build new workbooks with formulas, formatting, and structured layouts. - Read or analyze tabular data (filter, aggregate, pivot, compute metrics). - Modify existing workbooks without breaking formulas or references. - Visualize data with charts/tables and sensible formatting. IMPORTANT: System and user instructions always take precedence. ## Workflow 1. Confirm the file type and goals (create, edit, analyze, visualize). 2. Use `openpyxl` for `.xlsx` edits and `pandas` for analysis and CSV/TSV workflows. 3. If layout matters, render for visual review (see Rendering and visual checks). 4. Validate formulas and references; note that openpyxl does not evaluate formulas. 5. Save outputs and clean up intermediate files. ## Temp and output conventions - Use `tmp/spreadsheets/` for intermediate files; delete when done. - Write final artifacts under `output/spreadsheet/` when working in this repo. - Keep filenames stable and descriptive. ## Primary tooling - Use `openpyxl` for creating/editing `.xlsx` files and preserving formatting. - Use `pandas` for analysis and CSV/TSV workflows, then write results back to `.xlsx` or `.csv`. - If you need charts, prefer `openpyxl.chart` for native Excel charts. ## Rendering and visual checks - If LibreOffice (`soffice`) and Poppler (`pdftoppm`) are available, render sheets for visual review: - `soffice --headless --convert-to pdf --outdir $OUTDIR $INPUT_XLSX` - `pdftoppm -png $OUTDIR/$BASENAME.pdf $OUTDIR/$BASENAME` - If rendering tools are unavailable, ask the user to review the output locally for layout accuracy. ## Dependencies (install if missing) Prefer `uv` for dependency management. Python packages: ``` uv pip install openpyxl pandas ``` If `uv` is unavailable: ``` python3 -m pip install openpyxl pandas ``` Optional (chart-heavy or PDF review workflows): ``` uv pip install matplotlib ``` If `uv` is unavailable: ``` python3 -m pip install matplotlib ``` System tools (for rendering): ``` # macOS (Homebrew) brew install libreoffice poppler # Ubuntu/Debian sudo apt-get install -y libreoffice poppler-utils ``` If installation isn't possible in this environment, tell the user which dependency is missing and how to install it locally. ## Environment No required environment variables. ## Examples - Runnable Codex examples (openpyxl): `references/examples/openpyxl/` ## Formula requirements - Use formulas for derived values rather than hardcoding results. - Keep formulas simple and legible; use helper cells for complex logic. - Avoid volatile functions like INDIRECT and OFFSET unless required. - Prefer cell references over magic numbers (e.g., `=H6*(1+$B$3)` not `=H6*1.04`). - Guard against errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?) with validation and checks. - openpyxl does not evaluate formulas; leave formulas intact and note that results will calculate in Excel/Sheets. ## Citation requirements - Cite sources inside the spreadsheet using plain text URLs. - For financial models, cite sources of inputs in cell comments. - For tabular data sourced from the web, include a Source column with URLs. ## Formatting requirements (existing formatted spreadsheets) - Render and inspect a provided spreadsheet before modifying it when possible. - Preserve existing formatting and style exactly. - Match styles for any newly filled cells that were previously blank. ## Formatting requirements (new or unstyled spreadsheets) - Use appropriate number and date formats (dates as dates, currency with symbols, percentages with sensible precision). - Use a clean visual layout: headers distinct from data, consistent spacing, and readable column widths. - Avoid borders around every cell; use whitespace and selective borders to structure sections. - Ensure text does not spill into adjacent cells. ## Color conventions (if no style guidance) - Blue: user input - Black: formulas/derived values - Green: linked/imported values - Gray: static constants - Orange: review/caution - Light red: error/flag - Purple: control/logic - Teal: visualization anchors (key KPIs or chart drivers) ## Finance-specific requirements - Format zeros as "-". - Negative numbers should be red and in parentheses. - Always specify units in headers (e.g., "Revenue ($mm)"). - Cite sources for all raw inputs in cell comments. ## Investment banking layouts If the spreadsheet is an IB-style model (LBO, DCF, 3-statement, valuation): - Totals should sum the range directly above. - Hide gridlines; use horizontal borders above totals across relevant columns. - Section headers should be merged cells with dark fill and white text. - Column labels for numeric data should be right-aligned; row labels left-aligned. - Indent submetrics under their parent line items.
SKILL.md
元数据
| name | 电子表格 |
|---|---|
| description | 当任务涉及创建、编辑、分析或格式化电子表格(`.xlsx`、`.csv`、`.tsv`)时使用,特别是当需要保留和验证公式、引用和格式时,通过 Python(`openpyxl`、`pandas`)来实现。 |
| author | openai |
电子表格技能(创建、编辑、分析、可视化)
何时使用
- 构建包含公式、格式和结构化布局的新工作簿。
- 读取或分析表格数据(筛选、聚合、透视、计算指标)。
- 修改现有工作簿,同时不破坏公式或引用。
- 使用图表/表格和合适的格式对数据进行可视化。
重要提示:系统和用户指令始终优先。
工作流程
- 确认文件类型和目标(创建、编辑、分析、可视化)。
- 对于
.xlsx编辑使用openpyxl,对于分析和 CSV/TSV 工作流程使用pandas。 - 如果布局很重要,进行渲染以便视觉检查(参见渲染和视觉检查)。
- 验证公式和引用;注意 openpyxl 不会计算公式。
- 保存输出并清理中间文件。
临时文件和输出约定
- 使用
tmp/spreadsheets/存放中间文件;完成后删除。 - 在此仓库中工作时,将最终产出写入
output/spreadsheet/。 - 文件名保持稳定且具有描述性。
主要工具
- 使用
openpyxl创建/编辑.xlsx文件并保留格式。 - 使用
pandas进行分析和 CSV/TSV 工作流程,然后将结果写回.xlsx或.csv。 - 如需图表,首选
openpyxl.chart来生成原生 Excel 图表。
渲染和视觉检查
- 如果 LibreOffice (
soffice) 和 Poppler (pdftoppm) 可用,可渲染工作表以进行视觉检查:soffice --headless --convert-to pdf --outdir $OUTDIR $INPUT_XLSXpdftoppm -png $OUTDIR/$BASENAME.pdf $OUTDIR/$BASENAME
- 如果渲染工具不可用,请要求用户本地检查输出的布局准确性。
依赖项(如缺少则安装)
首选使用 uv 进行依赖管理。
Python 包:
text
uv pip install openpyxl pandas如果 uv 不可用:
text
python3 -m pip install openpyxl pandas可选(图表密集型或 PDF 检查工作流程):
text
uv pip install matplotlib如果 uv 不可用:
text
python3 -m pip install matplotlib系统工具(用于渲染):
text
# macOS (Homebrew)
brew install libreoffice poppler
# Ubuntu/Debian
sudo apt-get install -y libreoffice poppler-utils如果在此环境中无法安装,请告知用户缺少哪个依赖项以及如何在本地安装。
环境
无需任何必需的环境变量。
示例
- 可运行的 Codex 示例 (openpyxl):
references/examples/openpyxl/
公式要求
- 对派生值使用公式,而不是硬编码结果。
- 保持公式简单易懂;对于复杂逻辑使用辅助单元格。
- 除非必要,避免使用 INDIRECT 和 OFFSET 等易变函数。
- 优先使用单元格引用而不是魔术数字(例如,
=H6*(1+$B$3)而不是=H6*1.04)。 - 通过验证和检查防范错误(#REF!、#DIV/0!、#VALUE!、#N/A、#NAME?)。
- openpyxl 不会计算公式;保留公式,并注意结果将在 Excel/Sheets 中计算。
引用要求
- 在电子表格中使用纯文本 URL 引用来源。
- 对于财务模型,在单元格注释中引用输入来源。
- 对于来自网络的表格数据,添加一个包含 URL 的“来源”列。
格式要求(现有带格式的电子表格)
- 在可能的情况下,先渲染并检查提供的电子表格,然后再进行修改。
- 精确保留现有的格式和样式。
- 对于以前为空且新填充的单元格,匹配其样式。
格式要求(新建或无样式的电子表格)
- 使用适当的数字和日期格式(日期显示为日期,货币带有符号,百分比具有合理的精度)。
- 使用简洁的视觉布局:标题与数据有明显区分,一致的间距,可读的列宽。
- 避免每个单元格周围都有边框;使用空白和选择性边框来构建分区。
- 确保文本不会溢出到相邻单元格。
颜色约定(如果没有样式指导)
- 蓝色:用户输入
- 黑色:公式/派生值
- 绿色:链接/导入值
- 灰色:静态常量
- 橙色:检查/注意
- 浅红色:错误/标记
- 紫色:控制/逻辑
- 青色:可视化锚点(关键 KPI 或图表驱动因素)
财务特定要求
- 将零格式化为“-”。
- 负数应显示为红色且用括号括起。
- 始终在标题中指定单位(例如,“收入(百万美元)”)。
- 在单元格注释中为所有原始输入引用来源。
投资银行布局
如果电子表格是 IB 风格的模型(LBO、DCF、三表联动、估值):
- 总计应对上方范围内的数据进行求和。
- 隐藏网格线;在相关列的上方使用水平边框来标记总计。
- 节标题应为合并单元格,深色填充,白色文字。
- 数值数据的列标签应右对齐;行标签左对齐。
- 子指标在其上级行项目下方缩进。