سؤال

I have some code to loop through multiple workbooks:

wb = load_workbook(fileName)
for curTitle in wb.worksheets:
    ws = wb.get_sheet_by_name(name = curTitle.title)
    for row in ws.range('A1:C100'):
        for cell in row:
             #Do Something

However the range is different in every worksheet. Is there a way to get the last row that has data?

هل كانت مفيدة؟

المحلول

Here's the documentation for openpyxl.

If you look at the Worksheet module, you will see that your ws worksheet has functions like calculate_dimension(), get_highest_row(), and the like.

نصائح أخرى

Range("A1:C" & Range("A65536").End(xlup).Row)

assuming you have data up to the last row in col A

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top