How to delete unpopulated placeholder items using python-pptx

雨燕双飞 提交于 2020-01-14 07:46:10

问题


This is very simple, but I cannot find the actual method anywhere in the documentation or otherwise.

I am using the python-pptx module and all I need to do is delete a single placeholder item, an empty text box, on some slides (without having to create a completely new layout just for these slides) - the closest thing to an answer is here: http://python-pptx.readthedocs.io/en/latest/user/placeholders-understanding.html under Unpopulated vs. populated but it still does not say how to actually delete/remove the placeholder.

I've tried all the obvious methods .delete(), .remove(), etc.


回答1:


There is no API support for this, but if you delete the text box shape element, that should do the trick. It would be something like this:

textbox = shapes[textbox_idx]
sp = textbox.element
sp.getparent().remove(sp)

Using the textbox variable/reference after this operation is not likely to go well. But otherwise, I expect this will do the trick.



来源:https://stackoverflow.com/questions/39603318/how-to-delete-unpopulated-placeholder-items-using-python-pptx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!