I am trying to write a list to a row in Python using openpyxl, but to no avail.
The list contains say for example ten values. I need to open an existing worksheet, and write those ten values to their own cell, along one row.
I need to use openpyxl due to its functionality of overwriting existing worksheets compared to xlsxwriter where you can only create new worksheets.
Have a look here, scroll down to the heading Writing Values to Cells.
TLDR:
>>> import openpyxl
>>> wb = openpyxl.Workbook()
>>> sheet = wb['Sheet']
>>> sheet['A1'] = 'Hello world!'
>>> sheet['A1'].value
'Hello world!
or if you prefer
sheet.cell(row=2, column=3).value = 'hello world'
Update: changed to wb['Sheet'] syntax as per @charlieclark comment, thx
Update: To write mylist into row 2
for col, val in enumerate(mylist, start=1):
sheet.cell(row=2, column=col).value = val
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With