Python-docx段落。样式一无所获

时间:2018-10-01 16:01:49

标签: python python-docx

我需要阅读docx文件并根据段落样式对其进行解析。下面的代码在我的本地系统(Windows 10)上运行完美,但是当我在远程服务器(操作系统是Windows Server 2016但已完成所有设置)上运行此文档时,文档将返回``Nothing''(无)。我尝试使用para.style.name但结果相同。

任何帮助将不胜感激。

这是下面的代码段。

from docx import Document

# This is the Word Document on hard drive
doc = Document('C:\\Users\\agho10\\PycharmProjects\\SIMPLE.docx')

# Retrieve the doc title
for para in doc.paragraphs:
    parastyle = str(para.style)
    result = presentinlist(parastyle)
    # Capture the Document Title
    if "Project Title" in parastyle or "Title Centered" in parastyle:
        if docTitle == "":
           docTitle = para.text
           print(docTitle)

0 个答案:

没有答案