首先需要安装python-docx模块,然后使用以下代码读取docx文件内容:

import docx

def read_docx_file(file_path):
    doc = docx.Document(file_path)
    full_text = []
    for para in doc.paragraphs:
        full_text.append(para.text)
    return '\n'.join(full_text)

其中,file_path是docx文件的路径,读取后返回的是一个字符串,包含了文件中所有的文本内容。


原文地址: https://www.cveoy.top/t/topic/hduL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录