Automate Excel Reports with Python | OpenPyXL Step-by-Step TutorialCreateXL with Python

Опубликовано: 16 Май 2026
на канале: Code & Cells Lab
36
2

Want to automate Excel reports without even opening the file?

In this tutorial, we’ll learn how to use Python and OpenPyXL to create a styled Excel workbook step by step.

Today - We’ll start by building a simple Menu Analysis report with headers, data, and formatting.
In next session , we’ll explore how Python can connect with databases like PostgreSQL to pull data directly into Excel. By the end, you’ll see how programming can save time, reduce manual work, and make your reporting smarter.

Download PostgreSQL:
Windows: https://www.enterprisedb.com/download...

MAC: https://www.enterprisedb.com/download...

PY code we used:
----------------------------------------------------------------------
import openpyxl
from openpyxl.styles import Font, PatternFill
#import openpyxl.workbook

wb = openpyxl.Workbook()
sheet = wb.active
sheet.title = "Menu Analysis"

headers = ["Dish Name", "Cost", "Selling Price", "Profit"]
sheet.append(headers)

menu_data = [
["Butter Chicken", 150, 450, 300],
["Dal Makhani", 80, 280, 200],
["Panner Masala", 120, 320, 200],
["Garlic Naan", 20, 80, 60]
]

for row in menu_data:
sheet.append(row)

for cell in sheet[1]:
cell.font = Font(bold=True, color="FFFFFF")
cell.fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")

wb.save("Menu_Report.xlsx")
print("Excel created successfully")