[英]How to read the word(docx) in python?
import docx
doc = docx.Document("D:\Python\wordsim\word1.docx")
Generate error:产生错误:
D:\Python\wordsim\venv\Scripts\python.exe D:/Python/wordsim/wordsim.py Traceback (most recent call last): File "D:/Python/wordsim/wordsim.py", line 1, in import docx File "D:\Python\wordsim\venv\lib\site-packages\docx.py", line 30, in from exceptions import PendingDeprecationWarning ModuleNotFoundError: No module named 'exceptions' D:\Python\wordsim\venv\Scripts\python.exe D:/Python/wordsim/wordsim.py Traceback(最近一次调用最后):文件“D:/Python/wordsim/wordsim.py”,第 1 行,在导入 docx 文件“D:\Python\wordsim\venv\lib\site-packages\docx.py”,第 30 行,从异常导入 PendingDeprecationWarning ModuleNotFoundError: No module named 'exceptions'
When you install docx, use:安装 docx 时,请使用:
pip install python-docx
and not:并不是:
pip install docx
Exceptions module was removed in Python 3 and all standard exceptions were moved to builtin module.在 Python 3 中删除了异常模块,所有标准异常都移到了内置模块中。
pip install docx2txt pip 安装docx2txt
After you install this using CMD, it worked for me使用 CMD 安装后,它对我有用
import docx2txt导入 docx2txt
text = docx2txt.process("D:\Python\wordsim\word1.docx") text = docx2txt.process("D:\Python\wordsim\word1.docx")
print(text)打印(文本)
Add '\\' instead of '\', your code is correct.添加'\\'而不是'\',您的代码是正确的。
doc = docx.Document("D:\\Python\\wordsim\\word1.docx")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.