Generating Spreadsheets

Creates Excel spreadsheets (.xlsx) with formatted data, formulas, multiple sheets, or embedded charts. Use when the deliverable is a spreadsheet or the user asks for data in Excel.

aaravriyer193 Updated

File contents

Generating spreadsheets

Never hand-write .xlsx — build it with openpyxl.

pip install openpyxl
from openpyxl import Workbook
from openpyxl.styles import Font

wb = Workbook()
ws = wb.active
ws.title = "Data"
ws.append(["Name", "Revenue", "Growth"])
for cell in ws[1]:
    cell.font = Font(bold=True)
ws.append(["Acme", 120000, 0.18])

ws2 = wb.create_sheet("Summary")
ws2["A1"] = "Total"
ws2["B1"] = "=SUM(Data!B2:B1000)"

wb.save("/home/user/data.xlsx")

Columns don't auto-size — set widths explicitly if the sheet needs to be readable without manual resizing: ws.column_dimensions["A"].width = 18.

Use openpyxl (not pandas.to_excel) whenever the sheet needs formatting, formulas, or multiple styled sheets. pandas is fine only for a plain data dump with no styling need.

aaravriyer193/skills/tree/main/generating-spreadsheets commit c0c19194cc

Frequently asked questions

npx skillmds@latest add aaravriyer193/generating-spreadsheets