0

I am using the python-pptx library to create a table in pptx document. I want to add an image in the table cell, but I haven't found such option to do so.

I am adding cell using following code:

table.cell(0, 1).text = 'cell text'

How we can add an image in a table cell using python-pptx?

halfer
  • 19,824
  • 17
  • 99
  • 186
Navdeep Singh
  • 21
  • 1
  • 5
  • Please, add the code that you are trying to use. And have a look here: https://stackoverflow.com/help/mcve – Terru_theTerror Mar 20 '18 at 10:59
  • I didn't find any add_picture option in table cell properties. Please let me know the way to add a picture in a table cell in python-pptx. – Navdeep Singh Mar 20 '18 at 11:34
  • Each cell in the table is a shape. Get a reference to the shape of the cell and then you can add a picture fill to it. – Shyam Pillai Mar 20 '18 at 14:54
  • @ShyamPillai Thanks for your response. There is no shape attribute in cell. If I print cell it has following attributes: `['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_parent', '_tc', '_validate_margin_value', 'fill', 'margin_bottom', 'margin_left', 'margin_right', 'margin_top', 'part', 'text', 'text_frame', 'vertical_anchor']` – Navdeep Singh Mar 21 '18 at 07:21
  • Didn’t read the part that this was Python-Pptx. Looking at this: http://python-pptx.readthedocs.io/en/latest/api/table.html#table-objects. Cell Objects have a Fill which controls the formatting. Can you set the picture fill using that? – Shyam Pillai Mar 21 '18 at 13:27
  • Hi @ShyamPillai There is no parameter to add picture in fill property of cell object. fill has following attributes: `['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_fill', '_xPr', 'back_color', 'background', 'fore_color', 'from_fill_parent', 'pattern', 'patterned', 'solid', 'type'] ` – Navdeep Singh Mar 21 '18 at 14:50
  • Please add the above code to the question itself, by editing the question. – halfer Jul 22 '18 at 16:49

1 Answers1

1

I also would be interested in the answer to this:

One of my use cases is creating 4-up graphics slides and a 2 x 2 table would be a handy way.

The other use case - which I have for a presentation right now - is adding small images into a table.

The first real question is: Can Powerpoint even handle graphics in a table cell?

Martin Packer
  • 648
  • 4
  • 12
  • PowerPoint can definitely fill a cell with an image since it is tied to the fill formatting. Not familiar with Python-Pptx though. – Shyam Pillai Mar 21 '18 at 13:28
  • I did attempt something similar for a requirement I was addressing but it ended up being a futile attempt as to place an image on the slide we need to specify the position(x, y) and the height and width of the image. You can make it look like its within the cell by positioning it in such a way. – Varun Dec 06 '18 at 19:41