I am having one excel sheet which is used to read the data through python openpyxl...so in my script i have values that are hard coded as ws['E2':'AB3'] as AB3 is the last entry to be read...but now the sheet is updated and now last cell coordinate is AR3...how can i make the code generic so that every time sheet updates the code should work..?
Note(i find out total number of rows and column in sheet...what can i do)
rows = ws.max_row
column = ws.max_column
print(rows,column)
column_letter = get_column_letter(column)
print(column_letter)
Question: how can i make the code generic
Note: I assume you always want to start at 'E2'.
from openpyxl.utils import range_boundaries
# Define only start 'E2',
# all max_* values, last Row, Column, are returned by Default
min_col, min_row, max_col, max_row = range_boundaries('E2')# Iterate all Rows, starting at min_row == 2
for columns in worksheet.iter_rows(min_col=min_col, min_row=min_row, max_col=max_col, max_row=max_row):# Iterate all Columns, starting at min_col == 'E'for cell in columns:print('%s: cell.value=%s' % (cell, cell.value) )