读取Excle数据

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()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值