如何在文件xlsm/xlsx/docx中搜索python中的文本
以下代码只能在文件.txt中搜索Word,无法在文件XLSM/XLSX/DOCX中搜索Word。如何在文件XLSM/XLSX/DOCX中搜索文本?
import os
paths = r"C:\Test"
word = "Japanese"
for root, dirs, files in os.walk(paths):
for name in files:
with open(os.path.join(root, name),'r', errors='ignore') as fle:
my_files_content = fle.read()
if word in my_files_content:
print (fle.name)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用file.endswith('。txt','.py','.xml','.js')打开所有类型的文件。如果您仍然不清楚它,请使用以下链接来研究项目,它正在使用多种类型的文件进行相同的操作,
请找到此项目
确保仅为Windows编写此脚本
希望它有助于您的目标
you can use file.endswith('.txt', '.py', '.xml', '.js') to open all types of file. if you are still not clear with it please look into the project with below link it is doing the same things with multiple types of file
please find this project
https://github.com/dpakverma789/Projects/blob/Python_Projects/File_Search.py
make sure this script is written for windows only
hope it helps your goal