DeveloperBreeze

Excel Reports Development Tutorials, Guides & Insights

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

Automating Excel Reports with Python and OpenPyXL

Tutorial December 10, 2024
python

Let’s calculate the total sales for each product and add it as a new column:

# Add a new header for the total sales
sheet.cell(row=1, column=5, value="Total Sales")

# Calculate total sales for each product
for row in range(2, sheet.max_row + 1):
    jan = sheet.cell(row=row, column=2).value
    feb = sheet.cell(row=row, column=3).value
    mar = sheet.cell(row=row, column=4).value
    total = jan + feb + mar
    sheet.cell(row=row, column=5, value=total)

# Save the updated workbook
workbook.save('sales_data_with_totals.xlsx')