0Pricing
Python Academy · Lesson

Formulas and Charts

Add formulas and charts.

Beyond Static Values

Real spreadsheets calculate. openpyxl can write Excel formulas that recompute when data changes, and add charts that visualize the numbers directly inside the workbook.

This makes generated reports feel native to Excel users.

Writing a Formula

A formula is just a string starting with =. Assign it like any value: ws['B10'] = '=SUM(B2:B9)'. Excel evaluates it when the file opens.

openpyxl stores the formula text; it does not compute the result itself.

first_row, last_row = 2, 9
formula = '=SUM(B' + str(first_row) + ':B' + str(last_row) + ')'
print('Cell B10 ->', formula)

All lessons in this course

  1. Reading Workbooks
  2. Writing and Styling Cells
  3. Formulas and Charts
  4. Batch Processing Reports
← Back to Python Academy