Xlsx

by bobmatnyc718070a7d622No license77 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 2 months ago

Working with Excel files programmatically.

Instructions onlyDocuments & Office
AI-generated overview

Reference instructions for reading, writing, formatting and converting Excel XLSX files with Python and JavaScript libraries.

What it does
Provides code patterns for working with Excel spreadsheets programmatically, covering reading and writing cells and rows, styling headers and number formats, adding formulas, and converting between CSV and XLSX. It shows both openpyxl and pandas approaches in Python plus the xlsx library in JavaScript, and includes operations such as merging multiple workbooks and pivoting data. The deliverable is guidance and snippets rather than a runnable tool.
When to use it
Use when an agent needs to create, edit, format or extract data from Excel workbooks, or convert spreadsheets to and from CSV. It is also relevant when merging several Excel files or applying formulas and cell formatting.
Requirements
Python with openpyxl and pandas for the Python examples, or a JavaScript environment with the xlsx package for the JavaScript examples. No scripts are shipped; the skill is instructions and code samples only.

Excel/XLSX Manipulation

Working with Excel files programmatically.

Python (openpyxl)

Reading Excel

python
from openpyxl import load_workbook
wb = load_workbook('data.xlsx')ws = wb.active  # Get active sheet
# Read cellvalue = ws['A1'].value
# Iterate rowsfor row in ws.iter_rows(min_row=2, values_only=True):    print(row)

Writing Excel

python
from openpyxl import Workbook
wb = Workbook()ws = wb.activews.title = "Data"
# Write dataws['A1'] = 'Name'ws['B1'] = 'Age'ws.append(['John', 30])ws.append(['Jane', 25])
wb.save('output.xlsx')

Formatting

python
from openpyxl.styles import Font, PatternFill
# Bold headerws['A1'].font = Font(bold=True)
# Background colorws['A1'].fill = PatternFill(start_color="FFFF00", fill_type="solid")
# Number formatws['B2'].number_format = '0.00'  # Two decimals

Formulas

python
# Add formulaws['C2'] = '=A2+B2'
# Sum columnws['D10'] = '=SUM(D2:D9)'

Python (pandas)

Reading Excel

python
import pandas as pd
# Read sheetdf = pd.read_excel('data.xlsx', sheet_name='Sheet1')
# Read multiple sheetsdfs = pd.read_excel('data.xlsx', sheet_name=None)

Writing Excel

python
# Write DataFramedf.to_excel('output.xlsx', index=False)
# Multiple sheetswith pd.ExcelWriter('output.xlsx') as writer:    df1.to_excel(writer, sheet_name='Sheet1')    df2.to_excel(writer, sheet_name='Sheet2')

Data Transformation

python
# Filterfiltered = df[df['Age'] > 25]
# Group bygrouped = df.groupby('Department')['Salary'].mean()
# Pivotpivot = df.pivot_table(values='Sales', index='Region', columns='Product')

JavaScript (xlsx)

javascript
import XLSX from 'xlsx';
// Read fileconst workbook = XLSX.readFile('data.xlsx');const sheetName = workbook.SheetNames[0];const worksheet = workbook.Sheets[sheetName];
// Convert to JSONconst data = XLSX.utils.sheet_to_json(worksheet);
// Write fileconst newWorksheet = XLSX.utils.json_to_sheet(data);const newWorkbook = XLSX.utils.book_new();XLSX.utils.book_append_sheet(newWorkbook, newWorksheet, 'Data');XLSX.writeFile(newWorkbook, 'output.xlsx');

Common Operations

CSV to Excel

python
import pandas as pd
df = pd.read_csv('data.csv')df.to_excel('data.xlsx', index=False)

Excel to CSV

python
df = pd.read_excel('data.xlsx')df.to_csv('data.csv', index=False)

Merging Excel Files

python
dfs = []for file in ['file1.xlsx', 'file2.xlsx', 'file3.xlsx']:    df = pd.read_excel(file)    dfs.append(df)
combined = pd.concat(dfs, ignore_index=True)combined.to_excel('merged.xlsx', index=False)

Remember

  • Close workbooks after use
  • Handle large files in chunks
  • Validate data before writing
  • Use pandas for data analysis, openpyxl for formatting

Source and attribution

Source:bobmatnyc/claude-mpm-skillsinuniversal/data/xlsxat commit718070a

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal