Document XLSX Skill — Quick Reference
This skill enables creation, editing, and analysis of Excel spreadsheets programmatically. Claude should apply these patterns when users need to generate data reports, financial models, automate Excel workflows, or process spreadsheet data.
Modern Best Practices (Jan 2026):
- Treat spreadsheets as software: clear inputs/outputs, auditability, and versioning.
- Protect data integrity: control totals, validation, and traceability to sources.
- Accessibility: labels, contrast, structure; use Excel's Accessibility Checker; meet procurement/regulatory requirements when distributing externally.
- If distributing in the EU or regulated contexts, follow applicable accessibility requirements (often aligned with EN 301 549 / WCAG).
- Ship with a review loop and an owner (avoid "mystery models").
- Security: treat untrusted input/workbooks as hostile (formula injection, external links, hidden content, macros).
Quick Reference
| Task |
Tool/Library |
Language |
When to Use |
| Create XLSX |
ExcelJS |
Node.js |
Reports, data exports |
| Create XLSX |
openpyxl |
Python |
Read/write, modify existing files |
| Create XLSX |
XlsxWriter |
Python |
Write-only, rich formatting, charts |
| Data analysis |
pandas + openpyxl |
Python |
DataFrame to Excel with formatting |
| Read XLSX |
xlsx (SheetJS) |
Node.js |
Parse spreadsheets |
| Charts |
openpyxl/XlsxWriter |
Python |
Embedded visualizations |
| Styling |
ExcelJS/openpyxl |
Both |
Conditional formatting |
| Automation |
xlwings |
Python |
Excel installed, interactive workflows |
Guardrails and Caveats
- Formula calculation: libraries write formulas; Excel computes results when opened. If you need computed values server-side, calculate in code and write values (or use a dedicated formula engine).
- Pivot tables: programmatic creation is limited. Prefer pandas summaries (pivot tables as data) or Excel automation (xlwings/Office Scripts/VBA) if you truly need native pivots.
- Macros: openpyxl can preserve existing VBA (
keep_vba=True) but does not author macros; never generate or execute macros from untrusted input.
- Spreadsheet injection: never put untrusted strings into
formula fields; write them as text values and validate/sanitize user-provided data used in exports.
Core Operations
Create Spreadsheet (Node.js - exceljs)
import ExcelJS from 'exceljs';
const workbook = new ExcelJS.Workbook();
const sheet = workbook.addWorksheet('Sales Report');
// Headers with styling
sheet.columns = [
{ header: 'Product', key: 'product', width: 20 },
{ header: 'Quantity', key: 'qty', width: 12 },
{ header: 'Price', key: 'price', width: 12 },
{ header: 'Total', key: 'total', width: 15 },
];
// Style header row
sheet.getRow(1).font = { bold: true };
sheet.getRow(1).fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FF4472C4' }
};
// Add data
const data = [
{ product: 'Widget A', qty: 100, price: 10 },
{ product: 'Widget B', qty: 50, price: 25 },
];
data.forEach((item, index) => {
sheet.addRow({
product: item.product,
qty: item.qty,
price: item.price,
total: { formula: `B${index + 2}*C${index + 2}` }
});
});
// Add totals row
const lastRow = sheet.rowCount + 1;
sheet.addRow({
product: 'TOTAL',
total: { formula: `SUM(D2:D${lastRow - 1})` }
});
// Currency formatting
sheet.getColumn('price').numFmt = '$#,##0.00';
sheet.getColumn('total').numFmt = '$#,##0.00';
await workbook.xlsx.writeFile('report.xlsx');
Create Spreadsheet (Python - openpyxl)
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill
wb = Workbook()
ws = wb.active
ws.title = 'Sales Report'
# Headers
headers = ['Product', 'Quantity', 'Price', 'Total']
for col, header in enumerate(headers, 1):
cell = ws.cell(row=1, column=col, value=header)
cell.font = Font(bold=True, color='FFFFFF')
cell.fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')
# Data
data = [
('Widget A', 100, 10),
('Widget B', 50, 25),
('Widget C', 75, 15),
]
for row_idx, (product, qty, price) in enumerate(data, 2):
ws.cell(row=row_idx, column=1, value=product)
ws.cell(row=row_idx, column=2, value=qty)
ws.cell(row=row_idx, column=3, value=price)
ws.cell(row=row_idx, column=4, value=f'=B{row_idx}*C{row_idx}')
# Totals row
total_row = len(data) + 2
ws.cell(row=total_row, column=1, value='TOTAL')
ws.cell(row=total_row, column=4, value=f'=SUM(D2:D{total_row-1})')
# Number formatting
for row in range(2, total_row + 1):
ws.cell(row=row, column=3).number_format = '$#,##0.00'
ws.cell(row=row, column=4).number_format = '$#,##0.00'
wb.save('report.xlsx')
Read and Analyze (Python - pandas)
import pandas as pd
# Read Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
# Analysis
summary = df.groupby('Category').agg({
'Sales': 'sum',
'Quantity': 'mean'
}).round(2)
# Write to Excel with formatting
with pd.ExcelWriter('analysis.xlsx', engine='openpyxl') as writer:
df.to_excel(writer, sheet_name='Raw Data', index=False)
summary.to_excel(writer, sheet_name='Summary')
# Auto-adjust column widths
for sheet in writer.sheets.values():
for column in sheet.columns:
max_length = max(len(str(cell.value)) for cell in column)
sheet.column_dimensions[column[0].column_letter].width = max_length + 2
Add Charts (Python)
from openpyxl.chart import BarChart, Reference
chart = BarChart()
chart.title = 'Sales by Product'
chart.x_axis.title = 'Product'
chart.y_axis.title = 'Sales'
# Data range (assumes column D contains the series and row 1 is headers)
max_row = ws.max_row
data_ref = Reference(ws, min_col=4, min_row=1, max_row=max_row, max_col=4)
categories = Reference(ws, min_col=1, min_row=2, max_row=max_row)
chart.add_data(data_ref, titles_from_data=True)
chart.set_categories(categories)
chart.shape = 4
ws.add_chart(chart, 'F2')
Conditional Formatting
from openpyxl.formatting.rule import ColorScaleRule, FormulaRule
from openpyxl.styles import PatternFill
# Color scale (heatmap)
ws.conditional_formatting.add(
'D2:D100',
ColorScaleRule(
start_type='min', start_color='FF0000',
end_type='max', end_color='00FF00'
)
)
# Highlight cells above threshold
red_fill = PatternFill(start_color='FFCCCC', fill_type='solid')
ws.conditional_formatting.add(
'D2:D100',
FormulaRule(formula=['D2>1000'], fill=red_fill)
)
Common Formulas Reference
| Purpose |
Formula |
Example |
| Sum |
=SUM(range) |
=SUM(A1:A10) |
| Average |
=AVERAGE(range) |
=AVERAGE(B2:B100) |
| Count |
=COUNT(range) |
=COUNT(C:C) |
| Conditional sum |
=SUMIF(range,criteria,sum_range) |
=SUMIF(A:A,"Widget",B:B) |
| Lookup |
=VLOOKUP(value,range,col,FALSE) |
=VLOOKUP(A2,Data!A:C,3,FALSE) |
| If |
=IF(condition,true,false) |
=IF(B2>100,"High","Low") |
| Percentage |
=value/total |
=B2/SUM(B:B) |
Decision Tree
Excel Task: [What do you need?]
├─ Create new spreadsheet?
│ ├─ Simple data export → pandas to_excel()
│ ├─ Formatted report → exceljs or openpyxl
│ └─ With charts → openpyxl charts module
│
├─ Read/analyze existing?
│ ├─ Data analysis → pandas read_excel()
│ ├─ Preserve formatting → openpyxl load_workbook()
│ └─ Fast parsing → xlsx (SheetJS)
│
├─ Modify existing?
│ ├─ Add data → openpyxl (preserves formatting)
│ └─ Update formulas → openpyxl
│
└─ Complex features?
├─ Pivot tables → pandas summary tables or xlwings (native pivots)
├─ Data validation → openpyxl DataValidation
└─ Macros → preserve only; use xlwings for Excel automation
Do / Avoid (Jan 2026)
Do
- Separate Inputs / Calculations / Outputs (tabs or clear sections).
- Keep assumptions explicit (value + unit + source + date).
- Add control totals and reconciliation checks for imported data.
Avoid
- Hardcoded constants inside formulas without a documented assumption.
- Hidden rows/columns that change results without documentation.
- Sharing sheets with customer PII or secrets.
What Good Looks Like
- Structure: clear Inputs/Assumptions, Calculations, and Outputs separation (tabs or sections).
- Integrity: no
#REF!, broken named ranges, or hardcoded constants hidden in formulas.
- Traceability: every key output ties back to labeled inputs (units + source + date).
- Checks: control totals, reconciliations, and error flags that fail loudly.
- Review: independent review pass using
assets/spreadsheet-model-review-checklist.md.
Optional: AI / Automation
Use only when explicitly requested and policy-compliant.
- Generate first-pass formulas/charts; humans verify correctness and edge cases.
- Draft documentation tabs (assumptions, glossary); do not invent source data.
Navigation
Resources
- references/excel-formulas.md — Formula reference and patterns
- references/excel-formatting.md — Styling, conditional formatting
- references/excel-charts.md — Chart types and customization
- data/sources.json — Library documentation links
Templates
- assets/financial-report.md — Financial statement template
- assets/data-dashboard.md — Dashboard with charts
- assets/spreadsheet-model-review-checklist.md — Model QA checklist (assumptions, formulas, traceability)
Related Skills
1---2name: document-xlsx3description: Create, edit, audit, and extract Excel spreadsheets (.xlsx): generate reports/exports, apply formulas/formatting/charts/data validation, parse existing workbooks, and avoid spreadsheet risks (formula injection, broken links, hidden rows). Supports ExcelJS, openpyxl, pandas, XlsxWriter, and SheetJS.4---5
6# Document XLSX Skill — Quick Reference
7
8This skill enables creation, editing, and analysis of Excel spreadsheets programmatically. Claude should apply these patterns when users need to generate data reports, financial models, automate Excel workflows, or process spreadsheet data.
9
10**Modern Best Practices (Jan 2026)**:
11- Treat spreadsheets as software: clear inputs/outputs, auditability, and versioning.
12- Protect data integrity: control totals, validation, and traceability to sources.
13- Accessibility: labels, contrast, structure; use Excel's Accessibility Checker; meet procurement/regulatory requirements when distributing externally.
14- If distributing in the EU or regulated contexts, follow applicable accessibility requirements (often aligned with EN 301 549 / WCAG).
15- Ship with a review loop and an owner (avoid "mystery models").
16- Security: treat untrusted input/workbooks as hostile (formula injection, external links, hidden content, macros).
17
18---
19
20## Quick Reference
21
22| Task | Tool/Library | Language | When to Use |
23|------|--------------|----------|-------------|
24| Create XLSX | ExcelJS | Node.js | Reports, data exports |
25| Create XLSX | openpyxl | Python | Read/write, modify existing files |
26| Create XLSX | XlsxWriter | Python | Write-only, rich formatting, charts |
27| Data analysis | pandas + openpyxl | Python | DataFrame to Excel with formatting |
28| Read XLSX | xlsx (SheetJS) | Node.js | Parse spreadsheets |
29| Charts | openpyxl/XlsxWriter | Python | Embedded visualizations |
30| Styling | ExcelJS/openpyxl | Both | Conditional formatting |
31| Automation | xlwings | Python | Excel installed, interactive workflows |
32
33## Guardrails and Caveats
34
35- Formula calculation: libraries write formulas; Excel computes results when opened. If you need computed values server-side, calculate in code and write values (or use a dedicated formula engine).
36- Pivot tables: programmatic creation is limited. Prefer pandas summaries (pivot tables as data) or Excel automation (xlwings/Office Scripts/VBA) if you truly need native pivots.
37- Macros: openpyxl can preserve existing VBA (`keep_vba=True`) but does not author macros; never generate or execute macros from untrusted input.
38- Spreadsheet injection: never put untrusted strings into `formula` fields; write them as text values and validate/sanitize user-provided data used in exports.
39
40---
41
42## Core Operations
43
44### Create Spreadsheet (Node.js - exceljs)
45
46```typescript
47import ExcelJS from 'exceljs';
48
49const workbook = new ExcelJS.Workbook();
50const sheet = workbook.addWorksheet('Sales Report');
51
52// Headers with styling
53sheet.columns = [
54 { header: 'Product', key: 'product', width: 20 },
55 { header: 'Quantity', key: 'qty', width: 12 },
56 { header: 'Price', key: 'price', width: 12 },
57 { header: 'Total', key: 'total', width: 15 },
58];
59
60// Style header row
61sheet.getRow(1).font = { bold: true };
62sheet.getRow(1).fill = {
63 type: 'pattern',
64 pattern: 'solid',
65 fgColor: { argb: 'FF4472C4' }
66};
67
68// Add data
69const data = [
70 { product: 'Widget A', qty: 100, price: 10 },
71 { product: 'Widget B', qty: 50, price: 25 },
72];
73
74data.forEach((item, index) => {
75 sheet.addRow({
76 product: item.product,
77 qty: item.qty,
78 price: item.price,
79 total: { formula: `B${index + 2}*C${index + 2}` }
80 });
81});
82
83// Add totals row
84const lastRow = sheet.rowCount + 1;
85sheet.addRow({
86 product: 'TOTAL',
87 total: { formula: `SUM(D2:D${lastRow - 1})` }
88});
89
90// Currency formatting
91sheet.getColumn('price').numFmt = '$#,##0.00';
92sheet.getColumn('total').numFmt = '$#,##0.00';
93
94await workbook.xlsx.writeFile('report.xlsx');
95```
96
97### Create Spreadsheet (Python - openpyxl)
98
99```python
100from openpyxl import Workbook
101from openpyxl.styles import Font, PatternFill
102
103wb = Workbook()
104ws = wb.active
105ws.title = 'Sales Report'
106
107# Headers
108headers = ['Product', 'Quantity', 'Price', 'Total']
109for col, header in enumerate(headers, 1):
110 cell = ws.cell(row=1, column=col, value=header)
111 cell.font = Font(bold=True, color='FFFFFF')
112 cell.fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')
113
114# Data
115data = [
116 ('Widget A', 100, 10),
117 ('Widget B', 50, 25),
118 ('Widget C', 75, 15),
119]
120
121for row_idx, (product, qty, price) in enumerate(data, 2):
122 ws.cell(row=row_idx, column=1, value=product)
123 ws.cell(row=row_idx, column=2, value=qty)
124 ws.cell(row=row_idx, column=3, value=price)
125 ws.cell(row=row_idx, column=4, value=f'=B{row_idx}*C{row_idx}')
126
127# Totals row
128total_row = len(data) + 2
129ws.cell(row=total_row, column=1, value='TOTAL')
130ws.cell(row=total_row, column=4, value=f'=SUM(D2:D{total_row-1})')
131
132# Number formatting
133for row in range(2, total_row + 1):
134 ws.cell(row=row, column=3).number_format = '$#,##0.00'
135 ws.cell(row=row, column=4).number_format = '$#,##0.00'
136
137wb.save('report.xlsx')
138```
139
140### Read and Analyze (Python - pandas)
141
142```python
143import pandas as pd
144
145# Read Excel file
146df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
147
148# Analysis
149summary = df.groupby('Category').agg({
150 'Sales': 'sum',
151 'Quantity': 'mean'
152}).round(2)
153
154# Write to Excel with formatting
155with pd.ExcelWriter('analysis.xlsx', engine='openpyxl') as writer:
156 df.to_excel(writer, sheet_name='Raw Data', index=False)
157 summary.to_excel(writer, sheet_name='Summary')
158
159 # Auto-adjust column widths
160 for sheet in writer.sheets.values():
161 for column in sheet.columns:
162 max_length = max(len(str(cell.value)) for cell in column)
163 sheet.column_dimensions[column[0].column_letter].width = max_length + 2
164```
165
166### Add Charts (Python)
167
168```python
169from openpyxl.chart import BarChart, Reference
170
171chart = BarChart()
172chart.title = 'Sales by Product'
173chart.x_axis.title = 'Product'
174chart.y_axis.title = 'Sales'
175
176# Data range (assumes column D contains the series and row 1 is headers)
177max_row = ws.max_row
178data_ref = Reference(ws, min_col=4, min_row=1, max_row=max_row, max_col=4)
179categories = Reference(ws, min_col=1, min_row=2, max_row=max_row)
180
181chart.add_data(data_ref, titles_from_data=True)
182chart.set_categories(categories)
183chart.shape = 4
184
185ws.add_chart(chart, 'F2')
186```
187
188### Conditional Formatting
189
190```python
191from openpyxl.formatting.rule import ColorScaleRule, FormulaRule
192from openpyxl.styles import PatternFill
193
194# Color scale (heatmap)
195ws.conditional_formatting.add(
196 'D2:D100',
197 ColorScaleRule(
198 start_type='min', start_color='FF0000',
199 end_type='max', end_color='00FF00'
200 )
201)
202
203# Highlight cells above threshold
204red_fill = PatternFill(start_color='FFCCCC', fill_type='solid')
205ws.conditional_formatting.add(
206 'D2:D100',
207 FormulaRule(formula=['D2>1000'], fill=red_fill)
208)
209```
210
211---
212
213## Common Formulas Reference
214
215| Purpose | Formula | Example |
216|---------|---------|---------|
217| Sum | `=SUM(range)` | `=SUM(A1:A10)` |
218| Average | `=AVERAGE(range)` | `=AVERAGE(B2:B100)` |
219| Count | `=COUNT(range)` | `=COUNT(C:C)` |
220| Conditional sum | `=SUMIF(range,criteria,sum_range)` | `=SUMIF(A:A,"Widget",B:B)` |
221| Lookup | `=VLOOKUP(value,range,col,FALSE)` | `=VLOOKUP(A2,Data!A:C,3,FALSE)` |
222| If | `=IF(condition,true,false)` | `=IF(B2>100,"High","Low")` |
223| Percentage | `=value/total` | `=B2/SUM(B:B)` |
224
225---
226
227## Decision Tree
228
229```text
230Excel Task: [What do you need?]
231 ├─ Create new spreadsheet?
232 │ ├─ Simple data export → pandas to_excel()
233 │ ├─ Formatted report → exceljs or openpyxl
234 │ └─ With charts → openpyxl charts module
235 │
236 ├─ Read/analyze existing?
237 │ ├─ Data analysis → pandas read_excel()
238 │ ├─ Preserve formatting → openpyxl load_workbook()
239 │ └─ Fast parsing → xlsx (SheetJS)
240 │
241 ├─ Modify existing?
242 │ ├─ Add data → openpyxl (preserves formatting)
243 │ └─ Update formulas → openpyxl
244 │
245 └─ Complex features?
246 ├─ Pivot tables → pandas summary tables or xlwings (native pivots)
247 ├─ Data validation → openpyxl DataValidation
248 └─ Macros → preserve only; use xlwings for Excel automation
249```
250
251---
252
253## Do / Avoid (Jan 2026)
254
255### Do
256
257- Separate Inputs / Calculations / Outputs (tabs or clear sections).
258- Keep assumptions explicit (value + unit + source + date).
259- Add control totals and reconciliation checks for imported data.
260
261### Avoid
262
263- Hardcoded constants inside formulas without a documented assumption.
264- Hidden rows/columns that change results without documentation.
265- Sharing sheets with customer PII or secrets.
266
267## What Good Looks Like
268
269- Structure: clear Inputs/Assumptions, Calculations, and Outputs separation (tabs or sections).
270- Integrity: no `#REF!`, broken named ranges, or hardcoded constants hidden in formulas.
271- Traceability: every key output ties back to labeled inputs (units + source + date).
272- Checks: control totals, reconciliations, and error flags that fail loudly.
273- Review: independent review pass using `assets/spreadsheet-model-review-checklist.md`.
274
275## Optional: AI / Automation
276
277Use only when explicitly requested and policy-compliant.
278
279- Generate first-pass formulas/charts; humans verify correctness and edge cases.
280- Draft documentation tabs (assumptions, glossary); do not invent source data.
281
282## Navigation
283
284**Resources**
285- [references/excel-formulas.md](references/excel-formulas.md) — Formula reference and patterns
286- [references/excel-formatting.md](references/excel-formatting.md) — Styling, conditional formatting
287- [references/excel-charts.md](references/excel-charts.md) — Chart types and customization
288- [data/sources.json](data/sources.json) — Library documentation links
289
290**Templates**
291- [assets/financial-report.md](assets/financial-report.md) — Financial statement template
292- [assets/data-dashboard.md](assets/data-dashboard.md) — Dashboard with charts
293- [assets/spreadsheet-model-review-checklist.md](assets/spreadsheet-model-review-checklist.md) — Model QA checklist (assumptions, formulas, traceability)
294
295**Related Skills**
296- [../document-pdf/SKILL.md](../document-pdf/SKILL.md) — PDF generation from data
297- [../ai-ml-data-science/SKILL.md](../ai-ml-data-science/SKILL.md) — Data analysis patterns
298- [../data-sql-optimization/SKILL.md](../data-sql-optimization/SKILL.md) — Database to Excel workflows