【问题标题】:Extract particular word from docx table using python native library docx使用 python 本机库 docx 从 docx 表中提取特定单词
【发布时间】:2014-05-22 18:55:50
【问题描述】:

我的代码的主要目标是从 docx 表中提取特定的单词。

TextDoc.docx

Extract.py

from docx import *
mydoc = opendocx('/home/user/TestDoc.docx')    
search(mydoc,'Key1')

我的结果是 True,但我的目标类似于

get_value('Key1')

输出应该是

Value1

我们将不胜感激。

【问题讨论】:

    标签: python-2.7 unicode key-value python-docx


    【解决方案1】:

    我不相信您可以直接使用旧版本的 python-docx 做到这一点。您需要使用具有不同 API 的最新版本 (~0.5.0)。

    pip uninstall docx
    pip install python-docx
    

    这样的事情应该可以工作:

    from docx import Document
    
    document = Document('..path..')
    table = document.tables[0]
    cell = table.row[0].cells[0]
    paragraph = cell.paragraphs[0]
    text = paragraph.text
    

    python-docx 的文档在这里:http://python-docx.readthedocs.org/

    【讨论】:

    • 感谢解决方案进行了小修改。 cell = table.rows[0].cells[0]paragraph = cell.paragraphs[0]text1 = paragraph.textprint text1
    猜你喜欢
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多