Excel to PDF report automation
Turn a raw monthly sales Excel file into a formatted summary workbook and a one-page PDF report with charts, in one command.
What you'll learn
- âReading and writing Excel with pandas and openpyxl
- âPivot tables in pandas
- âGenerating charts and PDFs
What you'll build
- âReads any month's sales.xlsx
- âTotals by region, product and salesperson
- âFormatted Excel output with bold headers and number formats
- âPDF report with two charts and key numbers
Step-by-step guide
- 1
Create sample data
Make sales.xlsx with columns Date, Region, Product, Salesperson, Units, Price (or generate 500 rows with pandas and random).
- 2
Load and clean
pd.read_excel("sales.xlsx"); add Revenue = Units * Price; drop empty rows; parse dates.
- 3
Summarise
Use df.pivot_table(index="Region", columns="Product", values="Revenue", aggfunc="sum") and groupby("Salesperson").sum().
- 4
Write a formatted workbook
Use pd.ExcelWriter(engine="openpyxl") to write each summary to its own sheet, then style headers and set number formats with openpyxl.
- 5
Make charts
Plot revenue by region (bar) and by day (line) with matplotlib and save as PNG.
- 6
Build the PDF
Use matplotlib.backends.backend_pdf.PdfPages (or the reportlab library) to place the key numbers and both charts on one page.
- 7
One command
Wrap it in report.py --input sales.xlsx --month 2026-11 and print where the files were saved.
đ Make it stand out
- +Email the PDF automatically with smtplib
- +Compare with last month and highlight changes
- +Run it on a schedule