有以下店号
{1,2,3,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,44,45,46,47,49,50,51,52,53,54,56,57,60,62,63,64,65}
要求按照顺序新建sheet表,每店一个sheet页。
import openpyxl
wb = openpyxl.Workbook()
stores = [1,2,3,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,44,45,46,47,49,50,51,52,53,54,56,57,60,62,63,64,65]
for i in stores:
if i < 10:
wb.create_sheet("st0" + str(i))
else:
wb.create_sheet("st" + str(i))
print(wb.sheetnames)
wb.save("creat.xlsx")
生成的表格如下
===
以下是批量复制模板表
import openpyxl
wb = openpyxl.load_workbook("copy.xlsx")
stores = [1,2,3,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,44,45,46,47,49,50,51,52,53,54,56,57,60,62,63,64,65]
for i in stores:
ws = wb.copy_worksheet(wb["模板"])
if i < 10:
ws.title = "st0" + str(i)
else:
ws.title = "st" + str(i)
wb.remove(wb["模板"])
print(wb.sheetnames)
wb.save("copy-down.xlsx")