我想根据每一列的值,合并一堆 excel,可是老出问题,各种问题,求大神指点啊。
#!/usr/bin/env python
#coding=utf-8
import os
import xlrd
import xlwt
file = xlwt.Workbook()
ta = file.add_sheet('sheet1')
nr = 0
li = []
def isset(v):
try :
type (eval(v))
except :
return 0
else :
return 1
for fname in os.listdir("F:/同行交易记录 /直接搜索结果 /"):
#print(fname)
#print("F:/同行交易记录 /直接搜索结果 /"+fname)
lujing = "F:/同行交易记录 /直接搜索结果 /"+fname
data = xlrd.open_workbook(lujing)
table = data.sheet_by_index(0)
nrows = table.nrows
ncols = table.ncols
t = nrows
#print(table.row(0))
thead = table.row(0)
for x in range(len(thead)):
if str(thead[x]) == "text\:\'日期\'":
date = x
if str(thead[x]) == "text\:\'国内企业\'":
gnqy = x
if str(thead[x]) == "text\:\'日期\'":
gwqy = x
for i in range(nrows):
print(i)
if (isset("date")):
ta.write(nr+i-nrows+t,0,table.row(i)[date].value)
if (isset("gwqy")):
ta.write(nr+i-nrows+t,1,table.row(i)[gwqy].value)
if (isset("gnqy")):
ta.write(nr+i-nrows+t,2,table.row(i)[gnqy].value)
#li.append(table.row(i)[9].value)
nr += t
print(nr)
#print(li)
file.save('F:/同行交易记录 /直接搜索结果 /res.xls')
#!/usr/bin/env python
#coding=utf-8
import os
import xlrd
import xlwt
file = xlwt.Workbook()
ta = file.add_sheet('sheet1')
nr = 0
li = []
def isset(v):
try :
type (eval(v))
except :
return 0
else :
return 1
for fname in os.listdir("F:/同行交易记录 /直接搜索结果 /"):
#print(fname)
#print("F:/同行交易记录 /直接搜索结果 /"+fname)
lujing = "F:/同行交易记录 /直接搜索结果 /"+fname
data = xlrd.open_workbook(lujing)
table = data.sheet_by_index(0)
nrows = table.nrows
ncols = table.ncols
t = nrows
#print(table.row(0))
thead = table.row(0)
for x in range(len(thead)):
if str(thead[x]) == "text\:\'日期\'":
date = x
if str(thead[x]) == "text\:\'国内企业\'":
gnqy = x
if str(thead[x]) == "text\:\'日期\'":
gwqy = x
for i in range(nrows):
print(i)
if (isset("date")):
ta.write(nr+i-nrows+t,0,table.row(i)[date].value)
if (isset("gwqy")):
ta.write(nr+i-nrows+t,1,table.row(i)[gwqy].value)
if (isset("gnqy")):
ta.write(nr+i-nrows+t,2,table.row(i)[gnqy].value)
#li.append(table.row(i)[9].value)
nr += t
print(nr)
#print(li)
file.save('F:/同行交易记录 /直接搜索结果 /res.xls')