你的问题很可能存在于这里:
sheet_id = 3
cellval = enso.sheet_by_index(sheet_id).cell(20,2).value # row:20, column:0
检查以下内容:
确保sheet_id=3是你想要的(其中纸张索引从0开始),所以第三张纸张的索引= 2,除非你想要第四张纸张。
2 -检查cell(20,0)存在于所选工作表中(其中单元格(0,0)是第一个单元格)。
另外,不需要定义sheet_id
代替改变范围(2:第三片材,21:20张)>in range(2,21)其中:
range([start], stop[, step])
start: Starting number of the sequence.
stop: Generate numbers up to, but not including this number.
step: Difference between each number in the sequence.
并从每张纸上获取cellval,将cellval放入循环中。
最终的代码可能是:
output = 0
for sheet_id in range(2,21): # (starting at the 3rd sheet (index=2), stopping at 20 "21 not included")
cellval = enso.sheet_by_index(sheet_id).cell(20,0).value # row 20, column 0
#sheet_enso = enso_cp.get_sheet(sheet) # i don't know if you need that for something else
sheet_cp = book_cp.get_sheet(output)
sheet_cp.write(1, 1, cellval)
output = output + 1
book_cp.save(path)
再次检查cell(20,0)存在于所有源表以避免错误。