|
# -*- coding:utf-8 -*-
import xlrd
import xlwt
import glob
import os
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
workbook = xlrd.open_workbook('E:\\test3\\0.xls') #读取文件
print workbook.sheet_names()
sheet2 = workbook.sheet_by_index(0) #读取工作表
ncols = sheet2.ncols
book = xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet = book.add_sheet('2',cell_overwrite_ok=True)
list = [0,1,2,3,4]
list_1 = [1,2,3,4,5]
name_list = []
s = 0
for i in list: #读取列数据
cols = sheet2.col_values(i) #读取列数据
for y in cols[1:]: #从第二列开始读取写入
a = str(y).encode("utf-8")
b = a + '\n'
name_list.append(b) #取得数据list
print b
if
for x in range(len(name_list)): #将上面读取的数据循环写入
sheet.write(x+1,list_1,name_list[x]) #行数为X 列数为i 插入数据为name_list[x]
# sheet.write(x+1,0,filename_left)
name_list = []
s = s + 1
book.save('E:\\test3\\test.xls')
在if这添加依次读取第三列第几行数据的代码
|
|