| name | excel |
| description | Read, analyze, and generate Excel/CSV files. Triggers: excel, spreadsheet, csv, export data, create table, .xlsx, .csv. |
| effort | medium |
| context | inline |
/excel — Excel & CSV Processing
Read, analyze, and generate spreadsheet files. Always respond in the user's language.
Prerequisites
- CSV: built-in Python
csv module (no deps)
- XLSX: requires
pip install openpyxl
Algorithm
1. Determine Input
2. Read File
Detect format and read:
import csv
with open("file.csv", encoding="utf-8") as f:
reader = csv.DictReader(f)
rows = list(reader)
import openpyxl
wb = openpyxl.load_workbook("file.xlsx", data_only=True)
ws = wb.active
3. Analyze and Present
Report:
- Format, sheet count (xlsx), column names
- Row count
- Data types per column
- First 10 rows as markdown table
Ask user what to do next.
4. Generate File
When creating new spreadsheet:
import csv
with open("output.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(headers)
writer.writerows(data)
wb = openpyxl.Workbook()
ws = wb.active
ws.append(headers)
for row in data:
ws.append(row)
wb.save("output.xlsx")
5. Suggest Next Steps
Based on content:
- Data analysis → "Generate summary statistics? Visualize?"
- Import data → "Create migration script?"
- Export request → "Which format: .xlsx, .csv, .json?"
- Task list in spreadsheet → "Import as tasks with
/plan?"
Rules
- Always show column names and sample rows before processing
- Preserve data types (dates, numbers) when converting formats
- For large files (>1000 rows), show summary stats instead of all rows
- Suggest next:
/pdf for PDF data, /plan for task lists, /docs for data documentation
Gotchas
- openpyxl is not in stdlib — check if installed before attempting XLSX. CSV works without deps.
- Encoding — CSV files may be in
cp1251 (Russian Windows), not utf-8. Try utf-8 first, fall back to cp1251.
- Large XLSX files (>10MB) load slowly with openpyxl. Use
read_only=True mode for reading.