I have a table with a line at the top of the document. I need to replace that with just the line inside that table and make the line bold as well.
I am able to insert a line with add_paragraph and with add_heading as well.
But I want to add the line with making it bold.
This is what I was trying but I am facing errors.
para = document.add_paragraph().add_run(scheme)
para.bold = True
table._element.addprevious(para._p)
table._element.getparent().remove(table._element)
table._element.addprevious(para._p)
AttributeError: ‘Run’ object has no attribute ‘_p’
para = document.add_paragraph().add_run(scheme)
para.bold = True
table._element.addprevious(para)
table._element.getparent().remove(table._element)
table._element.addprevious(para)
TypeError: Argument ‘element’ has incorrect type (expected lxml.etree._Element, got Run)
Is there any way I can add_run() and add that paragraph too ??
add_run()
returns a Run
object, not a Paragraph
.
Here is the corrected code:
para = document.add_paragraph()
run = para.add_run(scheme)
run.bold = True
table._element.addprevious(para._element)
1