python查找excel中内容_python3.6 查找匹配excel文件内容

#-*- coding:utf-8 -*-

import os

import sys

import re

import numpy as np

import pandas as pd

import openpyxl

import xlrd

def checkText(file_dir,queryText):

wb = xlrd.open_workbook(file_dir) #打开excel表

#通过索引获取 从0开始

sheet = wb.sheet_by_index(1)

#通过名字获取某个sheet页的值

#sheet = wb.sheet_by_name('成果物)

#初始化count

count =0

#获取行数

nrows = sheet.nrows

#获取总列数

ncols = sheet.ncols

qcols = 4 #检索列 注意:数组从0开始

#print("The sum rows:%d" %nrows)

#print("The sum cols:%d" %ncols)

#获取列数

for i in range(nrows):

if re.search(queryText,sheet.cell_value(i,qcols)):

count = count +1

if count>0:

print(file_dir)

#根据文件夹 截取文件名称

def getFileList(path ):

allfileList = os.listdir(path)

count = 0

for file in allfileList:

filepath = os.path.join(path,file)

#只取以xlsx文件结尾的文件

if re.search(r'.xlsx', filepath):

#获取excel文件内容,并判断是否包含

checkText(filepath,'李剛')

if __name__ == '__main__':

path ="C:\\Users\SP000186\\Desktop\\test"

getFileList(path)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值