【问题标题】:reading heading from docx file using python使用python从docx文件中读取标题
【发布时间】:2019-03-07 07:09:40
【问题描述】:

我想从 docx 文件中读取标题,但文档模块没有读取标题的属性,我该怎么做

from docx import Document
def docheading():
    document = Document('C://Users//yousafzai//Desktop//Database//riya//riya//AbdulMateen.docx')
    headings=document.heading

【问题讨论】:

    标签: python-2.7 docx


    【解决方案1】:

    我也做了同样的事情。我做了这样的事情,你正在寻找的属性是 Style.name

    for paragraph in paragraphs:
        if paragraph.style.name=='Heading 1':
            print (paragraph.text)
    

    【讨论】:

      【解决方案2】:

      这是提取标题的方法:

      
      for paragraph in document.paragraphs:
          if paragraph.style.name=='Title':
              doc_title = paragraph.text
      

      【讨论】:

        【解决方案3】:

        尝试使用不同的库,例如 paradocx,它可以使用 style='Heading 1' 之类的东西从 Office XML 规范中读取 paradata

        【讨论】:

        • 你能解释一下吗
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-22
        • 1970-01-01
        相关资源
        最近更新 更多