excel.py 文件源码

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

项目:girlfriend 作者: chihongze 项目源码 文件源码
def execute(self, context, filepath, sheets=None, workbook_handler=None):
        if filepath is None:
            # ???????????
            filepath = "/tmp/{}_{}.xlsx".format(
                int(time.time()), random.randint(100, 999))
            workbook = xlsxwriter.Workbook(filepath)
        elif filepath.startswith("memory:"):
            output = StringIO()
            workbook = xlsxwriter.Workbook(output, {'in_memory': True})
            context[filepath[len("memory:"):]] = output
        else:
            workbook = xlsxwriter.Workbook(filepath)

        for sheet in sheets:
            sheet(context, workbook)

        if workbook_handler:
            workbook_handler(workbook)

        workbook.close()
        return filepath
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号