DeveloperBreeze

Data Automation Development Tutorials, Guides & Insights

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

Automating Excel Reports with Python and OpenPyXL

Tutorial December 10, 2024
python

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

from openpyxl.formatting.rule import CellIsRule
from openpyxl.styles import PatternFill

# Define the fill color
green_fill = PatternFill(start_color='C6EFCE', end_color='C6EFCE', fill_type='solid')

# Add conditional formatting
sheet.conditional_formatting.add(
    'E2:E100',
    CellIsRule(operator='greaterThan', formula=['4000'], fill=green_fill)
)

# Save the workbook
workbook.save('sales_report_highlighted.xlsx')