I am currently confused on how to insert a table in the middle of a document, like is it possible to change a text placeholder into a table in python?
For example:
*** PARAGRAPH ****
TEXT_PLACEHOLDER
*** PARAGRAPH****
I want to replace the TEXT_PLACEHOLDER with a table, is it possible?
I’ve done this and it creates the table but inserts it at the bottom of the next paragraph, skipping the second paragraph. The table was supposed to be before the second one but instead it is after it.
for paragraph in doc.paragraphs:
if placeholder in paragraph.text:
paragraph.text = paragraph.text.replace(placeholder, '')
table = doc.add_table(rows=3, cols=3)
for row in range(3):
for col in range(3):
table.cell(row, col).text = f"Row {row + 1}, Col {col + 1}"