import xlrd,xlwt
import os
import re
path = "安康出库/"
files = os.listdir(path)
def getKeyIndex(c_values, mystr):
for i in range(len(c_values)):
k = str(c_values[i]).find(mystr)
if(k!=-1):
return i
def read_excel(filename):
book = xlrd.open_workbook(filename)
sheet = book.sheet_by_index(0)
c_values = sheet.col_values(15)
cols = getKeyIndex(c_values, '机组')
# print(cols)
print(sheet.cell(cols-1, 14)) #读取指定单元格的数据
return sheet.cell(cols-1, 14)
fout = open('chuku.txt', 'w')
for file in files:
value = read_excel(path + file)
[nian,yue,ri,_,_] = re.split('[年月日]', file)
# print(re.split('[年月日]', file))
outstr = nian + '\t' + yue + '\t' + ri + '\t' + str(value) + '\n'
fout.write(outstr)
fout.close()