一个转表工作,主要是python操作excel 坑死了QAQ 上代码哭
__author__ = 'Victor Young'
import xlrd
data1 = xlrd.open_workbook('1302.xls')
data2 = xlrd.open_workbook('total.xlsx')
table1 = data1.sheet_by_name(u'Sheet1')
table2 = data2.sheet_by_name(u'Sheet1')
nrows1 = table1.nrows
nrows2 = table2.nrows
print nrows1,nrows2
from xlutils.copy import copy
wb = copy(data1)
ws = wb.get_sheet(0)
for i in range(nrows1):
for j in range(nrows2):
if table2.cell(j,1).value == table1.cell(i,1).value:
print "hello"
temp=table2.cell(j,10).value
ws.write(i,13,temp)
temp=table2.cell(j,11).value
ws.write(i,14,temp)
temp=table2.cell(j,12).value
ws.write(i,15,temp)
break
#print table1.cell(22,1)
#print table1.cell(i,1)
wb.save('new1302.xls')