I am coding a python function that has as input parameter certain excel range (e.g. "A1:B2"). How can I make python return a list of nº rows and nº columns from here?? (for instance if A1:B2 is the input, this list shall return [2,2])
This is what I did:
def return_rows_columns_from_excel_range(excel_range):
# import string
# import re
# excel range could be something like "A1:C15"
alphabet = list(string.ascii_uppercase)
first_cell = excel_range.split(":")[0]
second_cell = excel_range.split(":")[1]
column_1 = re.search('\D+',first_cell)[0]
column_2 = re.search('\D+',second_cell)[0]
row_1 = int(re.search('\d+',first_cell)[0])
row_2 = int(re.search('\d+',second_cell)[0])
columns = alphabet.index(column_2) - alphabet.index(column_1) + 1
rows = row_2 - row_1 + 1
output = [rows,columns]
return output
This is valid if ranges are like "A1:C15", but if the range is like "AA1:AC13" I am not very sure how to tackle it...