使用openpyxl复制整个工作表 [英] Copy whole worksheet with openpyxl
问题描述
请有人给我一个例子,如何复制 带有样式的整个工作表(来自行和列) 到同一工作簿中的第二个工作表? (也可以在新的工作簿中)
Please can someone give me an example, how to copy a whole worksheet with styles (from rows and columns) to a second worksheet in the same workbook ? (in a new workbook would also be possible)
谢谢.
P.S .:我尝试进行深度复制,但是在保存更改的数据单元时失败.
目的是:我尝试用数据填充一些工作表,而第一个工作表是我的模板.
P.S.: I tried to do a deepcopy, but that failed on saving changed data cells.
Purpose is: I try to fill some worksheets with my data and the first worksheet is my template.
我成功复制了值,但仅复制了某些样式. 我正在使用最新版本的openpyxl,所以请不要使用1.x方法.
I was successful in copying the values but only some styles. I am using the latest version of openpyxl, so please no 1.x methods.
推荐答案
Version 2.4 will allow you to do this: copy_worksheet
>>> source = wb.active
>>> target = wb.copy_worksheet(source)
对于较旧的版本,您可能可以从此处
For older ones you can probably copy the source code from here
更新:您不能简单地将此代码移植到库的较旧版本中
UPDATE: You can't simply graft this code into older versions of the library
这篇关于使用openpyxl复制整个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!