Search code examples
pythonexcelapplescriptxlwings

Insert image in Excel using xlwings


I try to insert an image to Excel using the xlwings / appscript on Mac using the following command :

 Sheet('sheet1').xl_sheet.shapes.pictures.open('test.png')

But the result is the opening of an Excel workbook with the image code. I have tried a lot of extensions but not found the correct one.

 xl_sheet.shapes.pictures.width
 xl_sheet.shapes.pictures.height
 xl_sheet.shapes.pictures.drop

Has someone any idea on how to deal with it and if it exists a documentation for AppleScript with Python?


Solution

  • This has now been released with xlwings v0.5.0:

    Example:

    import xlwings as xw
    pic = xw.Picture(1, 'picture_name')  # To manipulate an existing picture
    pic = xw.Picture.add('path/to/picture.jpg', sheet=1)  # add a new one
    

    See the docs for the details.