【发布时间】:2016-05-31 11:05:02
【问题描述】:
我想将我的数据从 python 传输到各种工作表中的 excel 文件。所以我需要更改工作表的名称以选择合适的工作表来书写。我已经编写了此代码,但它不接受我在ws = wb.add_sheet("Patch Size %s",%(wo)) 行中为我的工作表提供替代名称。
patch = [3, 5, 7, 9, 11, 13, 15, 17, 19, 25, 37, 49, 55, 60, 70, 80]
DATA = (("x", 1,),
("x",1),
("x",1),
("x",1 ),
("x",1 ),
("x",1 ),
("x",1 ),
("x",1 ),
("x",1 ),
("x", 1),
("x",1 ),
("x",1 ),
("x",1 ),
("x",1 ),
("x", 1),
("x",1),)
whch = 25
wb = xlwt.Workbook()
w0 = 0
while whch != patch[w0]:
w0 = w0+1
ws = wb.add_sheet("Patch Size %s",%(wo))
for i, row in enumerate(DATA):
for j ,col in enumerate(row):
if j == 0:
ws.write(i, j, col)
elif j == 1:
ws.write(i, which+j, col)
ws.col(0).width = 456 * max([len(row[0]) for row in DATA])
你知道我该怎么做吗?
谢谢。
【问题讨论】: