
python批处理多个excel文件,得出所有excel文件中某一列的和,具体程序如下:文件都在D:/excel中
importosimportxlrdos.chdir('D:\\excel')forjinos.popen('dir'):j=j.strip('\n')wb=xlrd.o...
import os
import xlrd
os.chdir('D:\\excel')
for j in os.popen('dir'):
j=j.strip('\n')
wb=xlrd.open_workbook(j)
table=wb.sheet_by_index(0)
numh=0.0
for i in range(1,table.nrows):
numh=table.cell(rowx=i,colx=1).value+numh
print numh
哪里错了
是不是文件迭代出错 展开
import xlrd
os.chdir('D:\\excel')
for j in os.popen('dir'):
j=j.strip('\n')
wb=xlrd.open_workbook(j)
table=wb.sheet_by_index(0)
numh=0.0
for i in range(1,table.nrows):
numh=table.cell(rowx=i,colx=1).value+numh
print numh
哪里错了
是不是文件迭代出错 展开
1个回答
展开全部
import os,xlrd
numh=0.0
for f in os.listdir('D:\\excel'):
print "file:",f
wb=xlrd.open_workbook(os.path.abspath(f))
table=wb.sheet_by_index(1)
for r in range(table.nrows):
numh=table.cell(r,0).value+numh
print 'numh:',numh
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询