首页 > 解决方案 > 基于python-docx,在特定文本python之后创建表

问题描述

我在 python 中看到了用于处理 word 文件的 python-docx 文档。对于本教程,我可以add_table在最后一行中使用创建表。

from docx import Document
from docx.shared import Inches
document = Document()
table = document.add_table(rows=1, cols=3)

当我检测到特定单词create table after line时,我想创建表。如何修改我的代码?

    document = Document('./my_document.docx')
    start = "create the table after line"
    for p in document.paragraphs:
        if(start in p.text):
            ##  Create the table in here
            p.add_table(nrows=2, cols=3)

标签: pythondocx

解决方案


推荐阅读