Python Forum
using openpyxl to insert an image in excel
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using openpyxl to insert an image in excel
#1
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.
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel Automation using Openpyxl pradyumnajpn 1 771 May-16-2023, 09:38 AM
Last Post: Larz60+
  openpyxl insert picture problem cools0607 2 1,388 May-03-2023, 06:48 AM
Last Post: cools0607
  is it possible to copy image from email and place into excel file? cubangt 3 1,212 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Openpyxl manipulate excel write formula SamLiu 0 1,002 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  openpyxl insert list with formulas Irv1n 1 1,516 Sep-16-2021, 08:10 AM
Last Post: Irv1n
  How to append a value to specific excel cell using openpyxl hobbyist 0 4,761 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  Append excel sheet using openpyxl TammyP 1 2,312 Feb-02-2021, 06:32 PM
Last Post: nilamo
  Openpyxl tkinter search a value in Excel column Heathcliff_1 0 3,211 Dec-02-2020, 04:35 PM
Last Post: Heathcliff_1
  Openpyxl: Excel formula & condition formatting removed JaneTan 0 3,557 Sep-25-2020, 07:02 AM
Last Post: JaneTan
  openpyxl - How can I copy some row from an excel file and paste them in another one? aquerci 2 17,285 Jun-07-2020, 04:26 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020