Skip to main content

Excel spreadsheets with openpyxl

Finance and operations teams still route truth through .xlsx workbooks. The openpyxl library reads and writes Office Open XML workbooks directly—no GUI required—which pairs naturally with ingestion scripts from Filesystem ops.

pip install openpyxl

📚 Prerequisites

  • Comfortable with looping rows conceptually (“record = dict of cells”).

🎯 What you'll master

  • Load workbooks selectively (read_only mode when scanning huge exports).
  • Write computed sheets programmatically validation teams can inspect.

Read cells

from openpyxl import load_workbook

wb = load_workbook("forecast.xlsx", data_only=True)
ws = wb["Q2"]
cell = ws["B4"]
print(cell.value)
wb.close()

Append rows safely

from openpyxl import Workbook

wb = Workbook()
ws = wb.active
ws.title = "run_log"

ws.append(["timestamp", "status", "records"])
ws.append(["2026-05-04T09:02Z", "ok", 842])
wb.save("reports/run_summary.xlsx")

💡 Key takeaways

  • data_only=True surfaces cached evaluated values from Excel formulas—opening without it shows formula strings instead.
  • For massive numeric grids, CSV + Pandas may outperform repeated cell visits—know which layer owns truth.

➡️ Next steps

Lightweight cron alternatives inside Python arrive in Scheduling with schedule.