Python 搜索本机内容包含“ip"的excel文件
时间: 2023-04-03 07:04:46 浏览: 45
你可以使用 Python 的 os 和 glob 模块来搜索本机内容包含“ip”的 Excel 文件。具体代码如下:
```python
import os
import glob
import pandas as pd
# 搜索当前目录及其子目录下所有的 Excel 文件
excel_files = glob.glob('**/*.xlsx', recursive=True)
# 遍历每个 Excel 文件,查找包含“ip”的单元格
for file in excel_files:
try:
df = pd.read_excel(file)
if 'ip' in df.values:
print(f'在文件 {file} 中找到了包含“ip”的单元格')
except:
pass
```
这段代码会输出所有包含“ip”的单元格所在的 Excel 文件路径。