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)