DeveloperBreeze

Data Processing Development Tutorials, Guides & Insights

Unlock 1+ expert-curated data processing tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your data processing skills on DeveloperBreeze.

Automating Excel Reports with Python and OpenPyXL

Tutorial December 10, 2024
python

from openpyxl.styles import Font, Alignment

# Bold headers
for col in range(1, 6):
    cell = sheet.cell(row=1, column=col)
    cell.font = Font(bold=True)

# Set column widths
sheet.column_dimensions['A'].width = 15
for col in ['B', 'C', 'D', 'E']:
    sheet.column_dimensions[col].width = 12

# Center-align headers
for col in range(1, 6):
    cell = sheet.cell(row=1, column=col)
    cell.alignment = Alignment(horizontal="center")

# Save the formatted workbook
workbook.save('sales_report_formatted.xlsx')

We’ll highlight products with total sales greater than 4000 in green.