Python Forum

Full Version: using openpyxl to insert an image in excel
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to insert photos in an excel table. From:

http://openpyxl.readthedocs.io/en/latest...g-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.
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.
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.