我正在从现有的 excel 创建一个新的 excel 。3 Sheets
在我的旧 excel 中有说first
, second
, third
. 我能够在基于某些条件的新 excel 中成功复制第一张工作表的内容,即我之前的代码while index < 3 :
工作得很好。对于工作表second
,third
我想按原样复制它们original excel sheet
。但是当开始复制工作second
表时,我收到一个错误:-
sheet1 = w.add_sheet('Info')
File "/usr/local/lib/python2.7/site-packages/xlwt/Workbook.py", line 331, in add_sheet
raise Exception("duplicate worksheet name %r" % sheetname)
我的代码如下: -
newexcel = "newexcel.xls"
count = 0
wb = xlrd.open_workbook('/home/sam/myexcel.xls')
w = Workbook()
sheet = w.add_sheet('Input_Resource')
index = 0
s = wb.sheet_by_index(index)
if index < 1 :
index =+ 1
for row in range(s.nrows):
coln =0
val = s.cell(row,coln).value
if val in MissingId :
mylist.append(val)
count += 1
else:
for col in range(s.ncols):
val = s.cell(row,col).value
sheet.write(row-count,col,val)
while index < 3 :
if index == 1 :
sheet1 = w.add_sheet('Info')
else :
sheet2 = w.add_sheet('Sheet3')
s = wb.sheet_by_index(index)
index =+ 1
for row in range(s.nrows):
coln =0
val = s.cell(row,coln).value
for col in range(s.ncols):
val = s.cell(row,col).value
if index == 1:
sheet1.write(row,col,val)
else :
sheet2.write(row,col,val)
w.save(newexcel)
任何帮助或提示表示赞赏:)