如果我理解正确,工作簿的add_sheet
方法将创建一个新工作表(并将其添加到工作簿中)。我有一个现有的excel模板(其中一个格式化的工作表用作添加信息的基础),我希望使用xlutils复制该模板,并使用新的工作表名称多次将其添加到新工作簿中。我怎样才能做到这一点?我查看了代码以了解如何将现有工作表添加到现有工作簿,但找不到类似的内容?
from xlrd import open_workbook
from xlutils.copy import copy
from xlwt import Workbook
rb = open_workbook('report3.xlt',formatting_info=True)
wb = copy(rb)
new_book = Workbook()
for distinct_employee in distinct_employees:
w_sheet = wb.get_sheet(0)
w_sheet.write(6,6,distinct_employee.name)
# give the sheet a new name (distinct_employee.id_number)
# add this sheet to new_book
book.save('all_employees.xls')
我发现用copy.deepcopy可以创建一个woorksheets的副本。也可以使用“工作簿”的“工作表”属性设置工作簿的工作表列表
使用您的示例,我将得到以下代码:
相关问题 更多 >
编程相关推荐