xlrd

#coding : utf-8
import numpy
import xlrd
import xlwt
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
aworkbook = xlrd.open_workbook(r'a.xlsx')
bworkbook = xlrd.open_workbook(r'b.xlsx')
sheet1 = aworkbook.sheet_by_index(0)
sheet2 = bworkbook.sheet_by_index(0)
len1 = len(sheet2.col_values(2))
print len1
data = []
for i in range(4,len1):
tmp = sheet2.row_values(i)
for j in range(len(tmp)):
tmp[j] = str(tmp[j])
tmp1 = tmp[:]
data.append(tmp1)
# for i in data:

print data
with open('r','w') as f:
for i in data:
f.write(','.join(i))
f.write('\n')
f = xlwt.Workbook()
sheet = f.add_sheet('sheet1')
for i in range(0, len(data)):
for j in range(len(data[i])):
sheet.write(i,j,data[i][j].decode('utf-8'))
try:
f.save('demo1.xlsx')
except Exception,e:
print e
# row3 = sheet2.col_values(2)
# col2 = sheet2.row_values(4)
# # print row3
#
# print row3
# print len(col2)
# for i in range(len(col2)):
# col2[i] = str(col2[i])
# r = ','.join(col2)
# r1 = ','.join(row3)
# r.encode('utf-8')
# r1.encode('utf-8')
# empList = r.split(',')
# print empList
posted @ 2017-03-13 00:17  我的大金金  阅读(298)  评论(0编辑  收藏  举报