def parse_xlsx(self, doc, sh=False):
workbook = load_workbook(filename = doc)
if sh:
sheet = workbook[sh]
else:
sheet = workbook['sheet1']
dimensions = sheet.dimensions
d1, d2 = dimensions.split(':')
cols = list(string.ascii_uppercase)
cols += [''.join(x) for x in product(cols,cols)] # to include further columns, named as combinations of characters
firstcol = ''.join([x for x in d1 if re.search(r'[A-Z]', x)])
lastcol = ''.join([x for x in d2 if re.search(r'[A-Z]', x)])
firstrow = int(''.join([x for x in d1 if re.search(r'[0-9]', x)]))
lastrow = int(''.join([x for x in d2 if re.search(r'[0-9]', x)]))
cols = cols[:cols.index(lastcol) + 1]
lines = []
for i in range(firstrow, lastrow+1):
line = []
for c in cols:
line.append(sheet[c + str(i)].value)
lines.append(line)
return lines
评论列表
文章目录