Skip to content

Instantly share code, notes, and snippets.

@revskill10
Forked from tnhu/excel_generator.py
Created May 7, 2023 16:54
Show Gist options
  • Save revskill10/5781be6626a435831b1462295e9de559 to your computer and use it in GitHub Desktop.
Save revskill10/5781be6626a435831b1462295e9de559 to your computer and use it in GitHub Desktop.
Open and Edit an Excel template using Python's openpyxl library
from openpyxl import load_workbook
wb = load_workbook('template.xlsx')
# grab the active worksheet
ws = wb.active
# Data can be assigned directly to cells
ws['A2'] = 'Tom'
ws['B2'] = 30
ws['A3'] = 'Marry'
ws['B3'] = 29
# Save the file
wb.save("sample.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment