Guest User

Untitled

a guest
Mar 19th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from pptx import Presentation
  2.  
  3. prs = Presentation('template.pptx')
  4.  
  5. slide4 = prs.slides[3]
  6.  
  7. for shape in slide4.placeholders:
  8. print('%d %s' % (shape.placeholder_format.idx, shape.name))
  9.  
  10. >>>
  11. 0 Title 3
  12. 10 Picture Placeholder 7
  13.  
  14. placeholder = slide4.placeholders[10] # idx key, not position
  15. picture = placeholder.insert_picture('test.jpg')
  16.  
  17. File "C:Python273libsite-packagespptxshapesplaceholder.py", line 323, in insert_picture
  18. pic = self._new_placeholder_pic(image_file)
  19. File "C:Python273libsite-packagespptxshapesplaceholder.py", line 334, in _new_placeholder_pic
  20. rId, desc, image_size = self._get_or_add_image(image_file)
  21. File "C:Python273libsite-packagespptxshapesplaceholder.py", line 345, in _get_or_add_image
  22. image_part, rId = self.part.get_or_add_image_part(image_file)
  23. File "C:Python273libsite-packagespptxpartsslide.py", line 42, in get_or_add_image_part
  24. image_part = self._package.get_or_add_image_part(image_file)
  25. File "C:Python273libsite-packagespptxpackage.py", line 50, in get_or_add_image_part
  26. return self._image_parts.get_or_add_image_part(image_file)
  27. File "C:Python273libsite-packagespptxpackage.py", line 159, in get_or_add_image_part
  28. image_part = self._find_by_sha1(image.sha1)
  29. File "C:Python273libsite-packagespptxpackage.py", line 171, in _find_by_sha1
  30. if image_part.sha1 == sha1:
  31. AttributeError: 'Part' object has no attribute 'sha1'
  32.  
  33. prs = Presentation()
  34. slide = prs.slides.add_slide(prs.slide_layouts[8])
  35. placeholder = slide.placeholders[1] # idx key, not position
  36. picture = placeholder.insert_picture('test.jpg')
  37. prs.save('new.pptx')
Add Comment
Please, Sign In to add comment