Reputation: 46
I was wondering if there is a way to determine the number of columns per row in Excel with Python. I know .max_row and .max_column show the maximum number of the respective fields. However, I need to pull the number of columns per row as they vary. The goal here is to create my own test program where all the Qs, As, and wrong As are in an excel spreadsheet and it is used as the database for the program. I'm not opposed to abandoning openpyxl if there is better tool.
Upvotes: 0
Views: 5229
Reputation: 390
For openpyxl 2.4 and up, you can do this:
for col in range(QAsheet.max_column):
print (row, len(QAsheet['row'])
Upvotes: 2
Reputation: 46
for row in range(QAsheet.max_row):
for column in range(QAsheet.max_column):
columnletter=openpyxl.cell.get_column_letter(column+1)
if(QAsheet["%s%s"%(columnletter,row+1)].value != None):
print(QAsheet["%s%s"%(columnletter,row+1)].value)
else:
pass
This seems to work. Thanks for the help!
Upvotes: 1