首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >docxtpl:插入带边框的新行

docxtpl:插入带边框的新行
EN

Stack Overflow用户
提问于 2019-07-16 11:26:39
回答 1查看 912关注 0票数 0

我有一个word文档page.docx,包含表和python文件file 1.py

代码语言:javascript
复制
from docxtpl import DocxTemplate

doc = DocxTemplate("page.docx")
context = { 'text': 'there could be your ad'}

a = doc.tables

for i in a:
    if i.cell(0,0).text == 'some_text_in_title':
        print(i.cell(0,0).text)
        i.add_row()

doc.render(context)
doc.save("page1.docx")

这将向文件中插入新行,但不会向这些新行添加边框。

如何在docxtpl中设置边框设置?

EN

回答 1

Stack Overflow用户

发布于 2022-04-08 21:44:03

python-docx模块更适合于修改Word文档中的现有表。

代码语言:javascript
复制
from docx import Document

document = Document(input_document_path)
tables = document.tables

for table in tables:
    for row in table.rows:
        if row.cells[0].text=="text_to_match":
            print(row.cells[0].text)
            table.add_row().cells

document.save(output_file_path)

新创建的带有add_row()函数的行保留原始表的样式属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57056194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档