Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pptx import Presentation
- prs = Presentation('template.pptx')
- slide4 = prs.slides[3]
- for shape in slide4.placeholders:
- print('%d %s' % (shape.placeholder_format.idx, shape.name))
- >>>
- 0 Title 3
- 10 Picture Placeholder 7
- placeholder = slide4.placeholders[10] # idx key, not position
- picture = placeholder.insert_picture('test.jpg')
- File "C:Python273libsite-packagespptxshapesplaceholder.py", line 323, in insert_picture
- pic = self._new_placeholder_pic(image_file)
- File "C:Python273libsite-packagespptxshapesplaceholder.py", line 334, in _new_placeholder_pic
- rId, desc, image_size = self._get_or_add_image(image_file)
- File "C:Python273libsite-packagespptxshapesplaceholder.py", line 345, in _get_or_add_image
- image_part, rId = self.part.get_or_add_image_part(image_file)
- File "C:Python273libsite-packagespptxpartsslide.py", line 42, in get_or_add_image_part
- image_part = self._package.get_or_add_image_part(image_file)
- File "C:Python273libsite-packagespptxpackage.py", line 50, in get_or_add_image_part
- return self._image_parts.get_or_add_image_part(image_file)
- File "C:Python273libsite-packagespptxpackage.py", line 159, in get_or_add_image_part
- image_part = self._find_by_sha1(image.sha1)
- File "C:Python273libsite-packagespptxpackage.py", line 171, in _find_by_sha1
- if image_part.sha1 == sha1:
- AttributeError: 'Part' object has no attribute 'sha1'
- prs = Presentation()
- slide = prs.slides.add_slide(prs.slide_layouts[8])
- placeholder = slide.placeholders[1] # idx key, not position
- picture = placeholder.insert_picture('test.jpg')
- prs.save('new.pptx')
Add Comment
Please, Sign In to add comment