python查询包含某字符串的excel

版权声明:小妖666个人笔记 https://blog.csdn.net/weixin_38883338/article/details/88959864
import os,sys,stat,xlrd
path=r"C:\git"
select = input("select:")
def del_file(path):
    ls = os.listdir(path)
    for i in ls:
        c_path = os.path.join(path, i)
        if os.path.isdir(c_path):
            del_file(c_path)
        elif os.path.splitext(c_path)[1] == '.xlsx' and r"~$" not in r''+c_path:
            workbook  = xlrd.open_workbook(c_path)
            print(c_path)
            worksheets = workbook.sheet_names()
            for sheet in worksheets:
                count = 0
                worksheet1 = workbook.sheet_by_name(u''+sheet)
                num_rows = worksheet1.nrows
                num_cols = worksheet1.ncols
                for rown in range(num_rows):
                    for coln in range(num_cols):
                        cell = worksheet1.cell_value(rown,coln)
                        if select in str(cell):
                            print(c_path)
                            count += 1
                            break
                    if count > 0:
                        break
                if  count > 0:
                    break
del_file(path)

猜你喜欢

转载自blog.csdn.net/weixin_38883338/article/details/88959864
今日推荐