# 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')
To make the report visually appealing, we’ll apply some formatting: