docreader.py 文件源码

python
阅读 86 收藏 0 点赞 0 评论 0

项目:quoll 作者: LanguageMachines 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号