要读取Word文档的内容,你可以使用python-docx库。首先,需要安装该库,可以使用以下命令进行安装:
pip install python-docx
安装完成后,你可以使用以下代码来读取Word文档的内容:
from docx import Document
# 打开文档
doc = Document('example.docx')
# 读取段落
for para in doc.paragraphs:
print(para.text)
# 读取表格
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
print(cell.text)
上述代码会打印出Word文档中的所有段落和表格内容。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>