Skip to content

Instantly share code, notes, and snippets.

@tnhu
Created April 22, 2016 20:38
Show Gist options
  • 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")
@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