- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
如果我理解正确,工作簿的 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 可以创建工作表的副本。还可以使用 _Workbook__worksheets 属性设置工作簿的工作表列表
使用你的例子我会有以下代码:
from copy import deepcopy
from xlrd import open_workbook
from xlutils.copy import copy as copy
from xlwt import Workbook
rb = open_workbook('report3.xlt',formatting_info=True)
wb = copy(rb)
new_book = Workbook()
sheets = []
for distinct_employee in distinct_employees:
w_sheet = deepcopy(wb.get_sheet(0))
w_sheet.write(6,6,distinct_employee.name)
# give the sheet a new name (distinct_employee.id_number)
w_sheet.set_name(distinct_employee.name)
# add w_sheet to the sheet list
sheets.append(w_sheet)
# set the sheets of the workbook
new_book._Workbook__worksheets = sheets
关于python - 如何使用 xlrd、xlwt 和 xlutils 将 "existing"工作表添加到工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5481474/
我正在使用 Python 2.5(并且需要继续使用它)并且已经下载了 xlrd 0.8.0 和 xlwt 0.7.2,它们似乎都工作正常。 我将需要读取和写入 Excel 电子表格,因此相信我也需要添
我正在尝试使用 Python 修改 Excel 文件,但我无法让 xlutils 包正常工作。当我尝试一个示例时(来自 this 线程): from xlutils.copy import copy
所以我有一个 Excel 电子表格,其中有一个我想要对电子表格进行排序的特定列。该列有 3 种不同的起始字母组合:B、C、E。我想按 B 排序,然后按 E 排序,然后按 C 开头的所有行排序。我确实需
我有一个包含许多相同格式的 excel 文件的文件夹,其中包含多张工作表。目标是遍历文件夹并将每个笔记本中的一张工作表移动到新笔记本,即从新工作簿中的每个 .xlsx 文件中结束一张工作表。我通常使用
我有一个现有的 Excel 工作簿 Workbook_A。我正在创建一个相同的工作簿 Workbook_B,然后将一些值插入到新工作簿的某些单元格中。 我正在做的事情的简化版本: from xlrd
我正在使用 xlutils 并复制工作表。下面的代码成功复制了第一个工作表并添加了 2 个副本,但是当我写入每个工作表时,它会将更改应用于所有工作表副本以及原始工作表。 因此在下面的示例中,所有 3
我有简单的代码可以使用 xlutils、xlrd、xlwt(从 python-excel.org 下载的新库)复制文件而不丢失格式。我收到如下错误: from xlwt.Workbook import
我正在尝试写入现有的 xls 文件,然后迭代同一文件的行,直到找到空白。 我了解如何通过代码执行此操作。 现在我的问题是,xlrd 是否“更新”它对工作表的引用?或者我是否必须在每次写入时通过打开工作
它们都是用于控制 Excel 的开源 Python 包(参见 python-excel )。我仍在努力理解他们的代码。如果有人能给出提示,他们如何以低杠杆方式连接到 Excel?通过 xml、Exce
我是 python 的新手(以及一般的编程)。 我在使用 xlrd、xlwt 和 xlutils 访问 xlsx 工作簿时遇到问题(它是一个常见问题,但我没有找到适合我的解决方案)。 我应该为 py-
我只想复制整个工作簿。有一些信息需要稍后添加,我很容易找到如何将信息添加到单个单元格等......但我还没有找到复制整个工作表的方法。也许我把这个问题过于复杂化了,但任何意见都会受到赞赏。谢谢! 最佳
是否有 xlrd、xlwt 和 xlutils 的替代方案用于在 python 中处理 MS Excel?据我所知,他们的许可不允许将其用于商业目的,我想知道除了使用 COM 之外是否还有其他选择。
如何使用 xlrd、xlwt 和 xlutils 模块编辑和保存现有 Excel 工作簿中的数据?有人可以提供一个示例代码来编辑和保存Excel工作簿中的数据吗? 我正在尝试将数据从一个工作簿放入另一
如果我理解正确,工作簿的 add_sheet 方法会创建一个新工作表(并将其添加到工作簿)。我有一个现有的 excel 模板(带有一个格式化工作表作为向其添加信息的基础),我想使用 xlutils 复
这个问题在这里已经有了答案: Preserving styles using python's xlrd,xlwt, and xlutils.copy (2 个答案) 关闭 8 年前。 简而言之,我
我尝试搜索很多地方,但没有看到任何关于如何使用 xlutils 或 xlwt 和 python 删除 excel 文件中现有工作表的示例代码片段。请问谁能帮帮我? 最佳答案 我刚刚处理了这个问题,虽然
我正在使用 xlrd、xlutils.copy 和 xlwt 打开一个模板文件,复制它,用新的填充它值,然后保存。 但是,似乎没有任何简单的方法可以保留单元格的格式;它总是被吹走并设置为空白。有什么简
大家好,先谢谢大家。 我有一个 python 脚本,我在其中打开模板 excel 文件,添加数据(同时保留样式)并再次保存。我希望能够在保存新的 xls 文件之前删除我没有编辑的行。我的模板 xls
我是一名优秀的程序员,十分优秀!