科研 Skill
Excel 工作簿处理
xlsx
读写编辑复杂 Excel 工作簿
Skill 说明
完整 Excel 工作簿读写编辑(公式 / 格式 / 财务模型 / 多 sheet / csv-tsv 输出) | 输入:.xlsx 文件 | 输出:读 / 写 / 编辑(公式 / 格式 / 多 sheet / CSV-TSV 输出)
SKILL.md
Requirements for Outputs
All Excel files
Professional Font
- Use a consistent, professional font (e.g., Arial, Times New Roman) for all deliverables unless otherwise instructed by the user
Zero Formula Errors
- Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)
Preserve Existing Templates (when updating templates)
- Study and EXACTLY match existing format, style, and conventions when modifying files
- Never impose standardized formatting on files with established patterns
- Existing template conventions ALWAYS override these guidelines
Financial models
Color Coding Standards
Unless otherwise stated by the user or existing template
Industry-Standard Color Conventions
- Blue text (RGB: 0,0,255): Hardcoded inputs, and numbers users will change for scenarios
- Black text (RGB: 0,0,0): ALL formulas and calculations
- Green text (RGB: 0,128,0): Links pulling from other worksheets within same workbook
- Red text (RGB: 255,0,0): External links to other files
- Yellow background (RGB: 255,255,0): Key assumptions needing attention or cells that need to be updated
Number Formatting Standards
Required Format Rules
- Years: Format as text strings (e.g., "2024" not "2,024")
- Currency: Use $#,##0 format; ALWAYS specify units in headers ("Revenue ($mm)")
- Zeros: Use number formatting to make all zeros "-", including percentages (e.g., "$#,##0;($#,##0);-")
- Percentages: Default to 0.0% format (one decimal)
- Multiples: Format as 0.0x for valuation multiples (EV/EBITDA, P/E)
- Negative numbers: Use parentheses (123) not minus -123
Formula Construction Rules
Assumptions Placement
- Place ALL assumptions (growth rates, margins, multiples, etc.) in separate assumption cells
- Use cell references instead of hardcoded values in formulas
- Example: Use =B5*(1+$B$6) instead of =B5*1.05
Formula Error Prevention
- Verify all cell references are correct
- Check for off-by-one errors in ranges
- Ensure consistent formulas across all projection periods
- Test with edge cases (zero values, negative numbers)
- Verify no unintended circular references
Documentation Requirements for Hardcodes
- Comment or in cells beside (if end of table). Format: "Source: [System/Document], [Date], [Specific Reference], [URL if applicable]"
- Examples:
- "Source: Company 10-K, FY2024, Page 45, Revenue Note, [SEC EDGAR URL]"
- "Source: Company 10-Q, Q2 2025, Exhibit 99.1, [SEC EDGAR URL]"
- "Source: Bloomberg Terminal, 8/15/2025, AAPL US Equity"
- "Source: FactSet, 8/20/2025, Consensus Estimates Screen"
XLSX creation, editing, and analysis
Overview
A user may ask you to create, edit, or analyze the contents of an .xlsx file. You have different tools and workflows available for different tasks.
Installation
uv pip install openpyxl pandas
Optional — faster Excel reading across formats with pandas 2.2+:
uv pip install python-calamine
For untrusted workbook files, harden openpyxl against XML expansion attacks:
uv pip install defusedxml
See openpyxl security guidance.
Formula Handling and Verification
Do not require any external spreadsheet application for ordinary spreadsheet tasks. Default workflows should read, clean, edit, format, export, and write formulas with pandas/openpyxl only.
Openpyxl preserves formulas as strings but does not calculate formula results. For ordinary deliverables, write or preserve formulas and let the user's spreadsheet application refresh them when opened.
Only start formula verification when the user explicitly asks to check formulas, validate calculated results, audit formula errors, or ensure a model has no Excel formula errors. In that case:
- Save the workbook with formulas preserved.
- Run static checks in Python for obvious issues such as missing sheets, broken references, empty referenced ranges, likely division by zero, and existing Excel error strings.
- Ask the user to open the workbook in Excel or WPS, wait for formulas to refresh, save, close the file, and confirm when done.
- Re-open the saved workbook with
openpyxl.load_workbook(path, data_only=True)and inspect cached values for#REF!,#DIV/0!,#VALUE!,#N/A,#NAME?, empty key outputs, or inconsistent sampled calculations. - If errors are found, fix the formulas and repeat the user-refresh/read-back loop.
Do not call external spreadsheet applications from this skill; it intentionally avoids desktop-app dependencies.
Reading and analyzing data
Data analysis with pandas
For data analysis, visualization, and basic operations, use pandas which provides powerful data manipulation capabilities:
import pandas as pd
# Read Excel (.xlsx default engine: openpyxl)
df = pd.read_excel('file.xlsx') # Default: first sheet
all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict
# Optional: calamine engine (pandas 2.2+) — faster, supports .xlsx/.xls/.xlsb/.xlsm/.ods
# df = pd.read_excel('file.xlsx', engine='calamine')
# Analyze
df.head() # Preview data
df.info() # Column info
df.describe() # Statistics
# Write Excel
df.to_excel('output.xlsx', index=False)
Large Excel files / performance
For large workbooks, roughly 50MB+ or when pd.read_excel is slow:
- First inspect workbook structure: sheet names, dimensions, headers, and needed columns.
- Avoid
sheet_name=Noneunless every sheet is required. - Use targeted
sheet_name,usecols,nrows, anddtype. - Prefer
engine="calamine"when available for faster reads. - For openpyxl inspection, use
read_only=Trueand iterate rows instead of loading the workbook normally. - Convert only needed sheets/columns to CSV or Parquet intermediates before heavy analysis when appropriate.
- For long-running extraction scripts, write progress logs with explicit flush, such as
print(..., flush=True)or line-buffered file logging. - If a background extraction task shows no log growth, file-size change, CPU activity, or staged output, change diagnostic action instead of repeatedly polling the same status.
Excel File Workflows
CRITICAL: Use Formulas, Not Hardcoded Values
Always use Excel formulas instead of calculating values in Python and hardcoding them. This ensures the spreadsheet remains dynamic and updateable.
❌ WRONG - Hardcoding Calculated Values
# Bad: Calculating in Python and hardcoding result
total = df['Sales'].sum()
sheet['B10'] = total # Hardcodes 5000
# Bad: Computing growth rate in Python
growth = (df.iloc[-1]['Revenue'] - df.iloc[0]['Revenue']) / df.iloc[0]['Revenue']
sheet['C5'] = growth # Hardcodes 0.15
# Bad: Python calculation for average
avg = sum(values) / len(values)
sheet['D20'] = avg # Hardcodes 42.5
✅ CORRECT - Using Excel Formulas
# Good: Let Excel calculate the sum
sheet['B10'] = '=SUM(B2:B9)'
# Good: Growth rate as Excel formula
sheet['C5'] = '=(C4-C2)/C2'
# Good: Average using Excel function
sheet['D20'] = '=AVERAGE(D2:D19)'
This applies to ALL calculations - totals, percentages, ratios, differences, etc. The spreadsheet should be able to recalculate when source data changes.
Common Workflow
- Choose tool: pandas for data, openpyxl for formulas/formatting
- Create/Load: Create new workbook or load existing file
- Modify: Add/edit data, formulas, and formatting
- Save: Write to file
- Formula verification (only when explicitly requested): Run static checks first. If calculated results must be verified, ask the user to open the workbook in Excel/WPS, save it after formulas refresh, then read cached values back with
openpyxl.load_workbook(path, data_only=True)and fix any errors found.
Creating new Excel files
# Using openpyxl for formulas and formatting
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = Workbook()
sheet = wb.active
# Add data
sheet['A1'] = 'Hello'
sheet['B1'] = 'World'
sheet.append(['Row', 'of', 'data'])
# Add formula
sheet['B2'] = '=SUM(A1:A10)'
# Formatting
sheet['A1'].font = Font(bold=True, color='FF0000')
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')
# Column width
sheet.column_dimensions['A'].width = 20
wb.save('output.xlsx')
Editing existing Excel files
# Using openpyxl to preserve formulas and formatting
from openpyxl import load_workbook
# Load existing file
wb = load_workbook('existing.xlsx')
sheet = wb.active # or wb['SheetName'] for specific sheet
# Working with multiple sheets
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
print(f"Sheet: {sheet_name}")
# Modify cells
sheet['A1'] = 'New Value'
sheet.insert_rows(2) # Insert row at position 2
sheet.delete_cols(3) # Delete column 3
# Add new sheet
new_sheet = wb.create_sheet('NewSheet')
new_sheet['A1'] = 'Data'
wb.save('modified.xlsx')
Formula Verification Workflow
Openpyxl can write and preserve formulas but does not evaluate them. Do not use external spreadsheet applications for automatic recalculation.
When the user explicitly asks for formula checking or result verification:
- Perform static checks before asking the user to refresh the workbook.
- Tell the user: "Please open the workbook in Excel or WPS, wait for formulas to refresh, save the file, close it, and tell me when it is saved."
- After the user confirms, load the workbook with
openpyxl.load_workbook(path, data_only=True)and scan cached values for errors such as#REF!,#DIV/0!,#VALUE!,#NAME?,#NULL!,#NUM!, and#N/A. - For important outputs, verify that cached values are present and sample-check simple calculations in Python when practical.
If the user does not perform the refresh/save step, explain that formula strings are preserved but cached results may be stale or unavailable.
Formula Verification Checklist
Quick checks to ensure formulas work correctly:
Essential Verification
- Test 2-3 sample references: Verify they pull correct values before building full model
- Column mapping: Confirm Excel columns match (e.g., column 64 = BL, not BK)
- Row offset: Remember Excel rows are 1-indexed (DataFrame row 5 = Excel row 6)
Common Pitfalls
- NaN handling: Check for null values with
pd.notna() - Far-right columns: FY data often in columns 50+
- Multiple matches: Search all occurrences, not just first
- Division by zero: Check denominators before using
/in formulas (#DIV/0!) - Wrong references: Verify all cell references point to intended cells (#REF!)
- Cross-sheet references: Use correct format (Sheet1!A1) for linking sheets
Formula Testing Strategy
- Start small: Test formulas on 2-3 cells before applying broadly
- Verify dependencies: Check all cells referenced in formulas exist
- Test edge cases: Include zero, negative, and very large values
Best Practices
Library Selection
- pandas: Best for data analysis, bulk operations, and simple data export
- openpyxl: Best for complex formatting, formulas, and Excel-specific features (current stable: 3.1.5)
Working with openpyxl
- Cell indices are 1-based (row=1, column=1 refers to cell A1)
- Use
data_only=Trueto read calculated values:load_workbook('file.xlsx', data_only=True) - Warning: If opened with
data_only=Trueand saved, formulas are replaced with values and permanently lost - For large files: Use
read_only=Truefor reading orwrite_only=Truefor writing - Formulas are preserved but not evaluated by openpyxl. For result verification, ask the user to refresh/save in Excel or WPS, then read cached values with
data_only=True
Working with pandas
- Specify data types to avoid inference issues:
pd.read_excel('file.xlsx', dtype={'id': str}) - For large files, read specific columns:
pd.read_excel('file.xlsx', usecols=['A', 'C', 'E']) - Handle dates properly:
pd.read_excel('file.xlsx', parse_dates=['date_column'])
Code Style Guidelines
IMPORTANT: When generating Python code for Excel operations:
- Write minimal, concise Python code without unnecessary comments
- Avoid verbose variable names and redundant operations
- Avoid unnecessary print statements
For Excel files themselves:
- Add comments to cells with complex formulas or important assumptions
- Document data sources for hardcoded values
- Include notes for key calculations and model sections
相关科研 Skill
中药材分子鉴定用ITS2等DNA条形码鉴定药材基原物种,处理多基原与降解样品局限。适用于药材真伪鉴别研究,不替代法定检验。
中药网络药理学用TCMSP等数据库构建成分-靶点-通路网络并做富集分析,批判性讨论方法学局限。适用于中药机制假设生成与论文方法复核。
中医术语标准与知识图谱建立中医药术语与WHO/ICD-11标准的映射,设计本体并用Neo4j构建知识图谱。适用于数据整合与科研检索,不作临床决策系统。
方剂配伍规律挖掘对方剂做药名规范化、关联规则与网络聚类分析,发现候选核心药组。适用于用药规律挖掘,结果仅为待验证假设,不作处方依据。
证候与症状数据分析对症状量表数据做术语规范、潜在类别与因子分析,探索统计学证候模式。适用于证候分型研究,结果不用于个体辨证诊断。
泵用混合物热力学计算Calculates thermodynamic properties and mixture phase behavior for pump applications using the thermo Python library’s DIPPR/NIST correlations. Use for VLE or mixture property calculations.
常见问题
Excel 工作簿处理能做什么?
完整 Excel 工作簿读写编辑(公式 / 格式 / 财务模型 / 多 sheet / csv-tsv 输出) | 输入:.xlsx 文件 | 输出:读 / 写 / 编辑(公式 / 格式 / 多 sheet / CSV-TSV 输出)。
如何安装Excel 工作簿处理?
在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「Excel 工作簿处理」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。
Excel 工作簿处理需要哪些权限?
该科研 Skill声明需要:本地文件。安装前会再次列出,由你确认后才会生效。
Excel 工作簿处理经过官方审核吗?
是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。