-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: remove single run/paragraph #144
Comments
Hi @theres, I think the API we'll use is .delete() on each individual object for which it's valid, so something like this: paragraph.runs[0].delete()
run.delete()
paragraph.delete()
# etc. ... In the meantime, this code should do the trick for plain content. The trickiness comes in when there are links to external content, like a picture or hyperlink: def delete_paragraph(paragraph):
p = paragraph._p
parent_element = p.getparent()
parent_element.remove(p)
# this second form is a little more direct, although perhaps not
# quite as clear on all the steps that are happening
def delete_run(run):
r = run._r
r.getparent().remove(r) You'll need to be careful about using any remaining reference to the paragraph after calling Dealing with these smaller details and edge cases will be some of the work that will go into the actual feature when we add it. Let us know how you go if you decide to use the workaround function :) |
Thanks! Anyway, great job and thank you again! |
Im stuck on this, prs.slides[slideIdx].shapes[1] is an textbox, how can i get rid from it? |
Hi Scanny, is it possible that you give a example how to use this function delete_paragraph()? i always got errors when i call it after i open a word file using Document() function, do I need do any other preparation before call this function? Thanks so much! |
@zhouaide0924 post a small example that doesn't work and describe the error you're getting in a post on StackOverflow tagged with the "python-docx" tag and I'll take a look. |
Hi Scanny, Thanks for your response, it is work now. I find I used it in a wrong way. Sorry for this issue. |
I make some pptx templates processing and this is really desired feature for me. API proposal:
and
The text was updated successfully, but these errors were encountered: