将工作表添加到现有Excel工作表,而不删除其他工作表 [英] Adding a sheet to an existing excel worksheet without deleting other sheet
本文介绍了将工作表添加到现有Excel工作表,而不删除其他工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图添加一个工作表到Excel文件:ex.xls,每当我删除所有以前制作的工作表。
I am trying to add a sheet to the excel file: ex.xls and whenever I do it deletes all the previously made sheets.
如何在不删除其他工作表的情况下将工作表添加到此Excel文件?
这是我创建表单的代码:
Here is my code to create a sheet:
import xlwt
import xlrd
wb = Workbook()
Sheet1 = wb.add_sheet('Sheet1')
wb.save('ex.xls')
推荐答案
我相信这是做你想做的唯一方法:
I believe this is the only way to do what you want:
import xlrd, xlwt
from xlutils.copy import copy as xl_copy
# open existing workbook
rb = xlrd.open_workbook('ex.xls', formatting_info=True)
# make a copy of it
wb = xl_copy(rb)
# add sheet to workbook with existing sheets
Sheet1 = wb.add_sheet('Sheet1')
wb.save('ex.xls')
这篇关于将工作表添加到现有Excel工作表,而不删除其他工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文