Skip to content

Instantly share code, notes, and snippets.

@tnhu
Created April 22, 2016 20:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tnhu/33a762d8c76aad25189114dffd9df6a8 to your computer and use it in GitHub Desktop.
Save tnhu/33a762d8c76aad25189114dffd9df6a8 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")
@YaminChoCho
Copy link

Thanks a million!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment