如何使用openpyxl将工作簿传播到另一个工作簿的工作表集

时间:2019-01-14 01:24:37

标签: python-3.x openpyxl

我想使用openpyxl将工作表散布到另一个工作簿的工作表集。我的代码是这个

import openpyxl
from openpyxl import load_workbook
# creat a empty workbook
wb = openpyxl.workbook()
# creat the source workbook file
fileS = open('path to source file', 'rb')
wbS = load_workbook(filename=fileS)
o=0
d={}
for i in range(1,31)
    k = 2
    # creat a holder to contains the worksheet objects
    d['ws{:d}'.format(i)] = wb.create_sheet('{:d}day'.format(i))
    # d[i] is the ith worksheet of the created  new workbook
    # but the d[i] is not correctly
    d[i]['B%d'%k] = wbS['B%d'%o].value
    o = o + 7
wb.save('path and filename to created files')

如何使用结构来表达所创建的新工作表的工作表。我使用了字典,但是它显示了无效的语法。

0 个答案:

没有答案