-1

我正在使用 python 3.4 创建一个表,我想让标题既粗体又加下划线。以下代码将使标题变为粗体:

table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Date Filmed:').bold = True
hdr_cells[2].paragraphs[0].add_run('Barcode Number:').bold = True

如果我将第 3 行更改为:

hdr_cells[0].paragraphs[0].add_run('Date Filmed:').underline = True

它会使文本加下划线,但不加粗。有没有办法让标题的文本既粗体又加下划线?

4

2 回答 2

3

您只需要一次添加一个布尔运行属性

run = hdr_cells[0].paragraphs[0].add_run('Date Filmed:')
run.bold = True
run.underline = True
于 2015-08-03T23:05:24.767 回答
0

打开一个word文档并在那里创建一个新的表格模板。在此模板中,您可以例如将第一行设置为粗体和下划线。

使用表格模板加载此文档:

document = Document('doc_with_table_template.docx')

添加具有此样式的表格:

table_positionen = document.add_table(3, 2))
table_positionen.style = 'YOUR TEMPLATE NAME'

在其中添加文本:

hdr_cells = table_positionen.rows[0].cells
for i in range(2): # cols
        pa = hdr_cells[i].paragraphs[0].add_run("Hello")
        pa.alignment = WD_ALIGN_PARAGRAPH.RIGHT

有了这个,您还可以根据需要设置对齐方式。

于 2020-11-22T21:22:36.830 回答