excel.py 文件源码

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

项目:gtool 作者: gtoolframework 项目源码 文件源码
def __writexls__(self, filename="output.xlsx", outputdict={}):

        if outputdict is None:
            raise ValueError('An output argument was expected')

        if not isinstance(outputdict, dict):
            raise TypeError('Was expecting a dictionary for outputdict but got a %s' % type(dict))

        extension = '.xlsx'
        if not filename.endswith(extension):
            filename += extension

        #TODO check location and filename are valid

        workbook = xlsxwriter.Workbook(filename)

        for sheet, grid in sorted(outputdict.items()):
            worksheet = workbook.add_worksheet(name=sheet[:32]) #worksheet name cannot be more than 32 chars long
            if not isinstance(grid, Matrix):
                raise TypeError('Expected a Matrix but got a %s' % type(grid))
            for i, row in enumerate(grid):
                worksheet.write_row(i, 0, row)

        workbook.close()

        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号