I have a docx file and I need to remove all content from a given line.
From what I can see I can iterate over paragraphs or tables.
However I think that I need some universal element to iterate over to remove all content from a specific point (element) in the document.
Next I would like to check if this element is a paragraph or a table to execute relevant deletion code.
I have found this code in GitHub Issues for deleting a paragraph (which doesn't seem to work anymore):
def delete_paragraph(paragraph):
p = paragraph._element
p.getparent().remove(p)
paragraph._p = paragraph._element = None
but I can still delete paragraph runs:
runs = paragraph.runs
for run in runs:
run.text = ""
r = run._r
r.getparent().remove(r)
Didn't tested, but I have seen code for deleting table content somewhere.
So, is it possible to perform such an action?
Alternative description of what I want to achieve would be to split existing document by line with tag ex. spit here
.