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")
@andermoran
Copy link

Thanks!

@Darren200824
Copy link

This is very useful. It's almost the easiest way on the Internet.

@cybermonk00
Copy link

Extremely Thanks

@abhay-kum
Copy link

how can we insert the data using row and column number ?

@SamTop
Copy link

SamTop commented Oct 13, 2021

how can we insert the data using row and column number ?
sheet.cell(row=row, column=col).value = 'value'

@YaminChoCho
Copy link

Thanks a million!

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