Skip to content

Working with Excel - openpyxl Basics

openpyxl lets you work with .xlsx files:

  • create workbooks
  • read/write cells
  • adjust styles
excel_create.py
from openpyxl import Workbook
 
wb = Workbook()
ws = wb.active
ws.title = "Report"
 
ws["A1"] = "Name"
ws["B1"] = "Score"
 
ws.append(["Alice", 95])
ws.append(["Bob", 88])
 
wb.save("report.xlsx")
excel_read.py
from openpyxl import load_workbook
 
wb = load_workbook("report.xlsx")
ws = wb["Report"]
 
print(ws["A2"].value, ws["B2"].value)
  • Keep a template .xlsx if you need complex formatting
  • For CSV, prefer the csv module or pandas

Exercise 2 – Join Paths with os.path.join

Section titled “Exercise 2 – Join Paths with os.path.join”

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading