使用openpyxl将工作表追加到现有的excel文件中 [英] Append a sheet to an existing excel file using openpyxl

查看:751
本文介绍了使用openpyxl将工作表追加到现有的excel文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这篇文章使用xlutils.copy附加了一张纸:

I saw this post to append a sheet using xlutils.copy:

https://stackoverflow.com/a/38086916/2910740

是否有仅使用openpyxl的解决方案?

Is there any solution which uses only openpyxl?

推荐答案

我找到了解决方案.非常简单:

I found solution. It was very easy:

def store_excel(self, file_name, sheet_name):
    if os.path.isfile(file_name):
        self.workbook = load_workbook(filename = file_name)
        self.worksheet = self.workbook.create_sheet(sheet_name)
    else:
        self.workbook = Workbook()
        self.worksheet = self.workbook.active
        self.worksheet.title = time.strftime(sheet_name)
    .
    .
    .
    self.worksheet.cell(row=row_num, column=col_num).value = data

这篇关于使用openpyxl将工作表追加到现有的excel文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆