I have data in file1.xlsx (sheet 3) and a picture in file2.xlsx (sheet 1).
I want to place that picture next to data in sheet3.
I have tried to use openpyxl.drawing.image to insert image but it didn't work:
IOError: cannot identify image file
Then I tried xlsxwriter but it doesn't work on an existing workbook, so I end up with 2 workbooks.
Basically you need to extract the image from the source Excel sheet in
file2.xlsxand then insert it intofile1.xlsx. This can be done by using the worksheet._imagesattribute which is aprotected attribute.Your code operation may depend on how many images and whether you know the location of them in
file2.xlsx.In the code example below we assume 1 image in
file2.xlsx. The image is placed infile1.xlsxat thedestination_celllocation which I have set to 'G1' for this example.If there is more than 1 image in file2.xlsx you would need to loop through the images in
ws_source._imagesand find the one you needNote; if you do not wish to use a
protected attributein your code directly you can use the openpyxl-image-loader wrapper for Openpyxl. It essentially creates a class that does the same thing but you do need to know the location cell of the image. The link gives an example how to utilise.