欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python查询包含某字符串的excel

程序员文章站 2023-12-21 16:37:34
...
import os,sys,stat,xlrd
path=r"F:\360Downloads"
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':
            workbook  = xlrd.open_workbook(c_path)
            worksheets = workbook.sheet_names()
            for sheet in worksheets:
                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)
del_file(path)

 

上一篇:

下一篇: