Python Forum
using openpyxl to insert an image in excel - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: using openpyxl to insert an image in excel (/thread-4781.html)



using openpyxl to insert an image in excel - Pedroski55 - Sep-08-2017

I want to insert photos in an excel table. From:

http://openpyxl.readthedocs.io/en/latest/usage.html#inserting-an-image

I get:

Quote:from openpyxl.drawing.image import Image
ws.add_image(img, 'A1')

So I tried in the interactive shell:

Quote:>>>from openpyxl.drawing.image import Image
>>> imXl.add_image(image, 'A2')
Traceback (most recent call last):
File "<pyshell#79>", line 1, in <module>
imXl.add_image(image, 'A2')
AttributeError: 'Workbook' object has no attribute 'add_image'

Obviously the attribute '.add_image(image, 'cell') is deprecated.

Does anyone know what it looks like now? I could switch to xwlt but then I've got to find out how that works. I know the important parts of openpyxl already now.


RE: using openpyxl to insert an image in excel - Larz60+ - Sep-08-2017

full docs are here: https://openpyxl.readthedocs.io/en/default/

I couldn't see where add_image was depreciated.
I did see that it is only available if opened in write mode.


RE: using openpyxl to insert an image in excel - Pedroski55 - Sep-09-2017

Thanks, I got it to work. I should not have used imXl, that was the workbook, not the active sheet.

It's just, the image inserted is 3 times bigger than it should be. Not a python problem I think. Something to do with how Libre Office converts values.