我有一个word文档page.docx,包含表和python文件file 1.py。
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中设置边框设置?
发布于 2022-04-08 21:44:03
python-docx模块更适合于修改Word文档中的现有表。
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()函数的行保留原始表的样式属性。
https://stackoverflow.com/questions/57056194
复制相似问题