I am working with a big excel file. I am using
wb = load_workbook(filename='my_file.xlsx')
ws = wb['Sheet1']
I don't want to alter the worksheet in any way. I just want to take data from several columns and work with them.
My understanding is that I can't just call a column and use .tolist()
because all the values are stored in excel.
Bernie's answer, I think, was for a slightly older version of OpenPyxl. Worksheet.columns
no longer returns tuples but rather, is a generator. The new way to access a column is Worksheet['AlphabetLetter']
.
So the rewritten code is:
mylist = []
for col in ws['A']:
mylist.append(col.value)
Based on your comment here's one thing you can do:
mylist = []
for col in ws.columns[0]:
mylist.append(col.value)
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