如何使用 Python docx 使 table 的 header 行变为粗体?
How to make header rows for table bold using Python docx?
我使用 Python docx 库创建了一个 table,并希望将 header 行设为粗体。这是我正在使用的代码:
a= doc.add_table(rows=5, cols=7)
heading_cells = a.rows[0].cells
w = heading_cells[1].text.add_run('Col 1')
w.bold = True
i = heading_cells[2].text = 'Col 2'
i.bold = True
这是给我的信息:
AttributeError: 'str' object has no attribute 'add_run'
我正在努力寻找正确的语法,有什么想法吗?
有多种选择,但这个可能适合您的情况:
table = document.add_table(rows=5, cols=7)
heading_cells = table.rows[0].cells
run = heading_cells[1].paragraphs[0].add_run('Col 1')
run.bold = True
我使用 Python docx 库创建了一个 table,并希望将 header 行设为粗体。这是我正在使用的代码:
a= doc.add_table(rows=5, cols=7)
heading_cells = a.rows[0].cells
w = heading_cells[1].text.add_run('Col 1')
w.bold = True
i = heading_cells[2].text = 'Col 2'
i.bold = True
这是给我的信息:
AttributeError: 'str' object has no attribute 'add_run'
我正在努力寻找正确的语法,有什么想法吗?
有多种选择,但这个可能适合您的情况:
table = document.add_table(rows=5, cols=7)
heading_cells = table.rows[0].cells
run = heading_cells[1].paragraphs[0].add_run('Col 1')
run.bold = True