简体   繁体   中英

maximum column count in specific row

I need to know the number of used (non-empty) columns in a specific row, let's say row no 4.

len(sheet[4])

gives me the number of columns used in total, not just of the 4th row

sheet[4].max_column

doesn't work. Does anyone have an idea?

You should really think of a spreadsheet as always being 16,384 columns and 1,000,000 rows. Anything else is essentially dependent upon implementation specifics.

If you follow this logic through then you can find the highest row in any particular column by counting down from ws.max_column to the first non-empty cell. You can do this with column indexing:

for cell in reversed(ws[4]):
     if cell.value is not None:
         break

print("max row for column {0} is {1}".format(cell.col_idx, cell.row)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM