I'm trying to insert images with OpenPyxl to a Excel file that has already images in it (in different sheets in my case). If I do so, the existing images disappear.
Sample code:
import openpyxl
from openpyxl import load_workbook
wb = openpyxl.Workbook()
ws1 = wb.create_sheet("MySheet1")
img1 = openpyxl.drawing.image.Image('test1.png')
img1.anchor = ws1.cell(row=2, column=2).coordinate
ws1.add_image(img1)
wb.save('test_output.xlsx')
wb = load_workbook(filename='test_output.xlsx')
ws2 = wb.create_sheet("MySheet2")
img2 = openpyxl.drawing.image.Image('test2.png')
img2.anchor = ws2.cell(row=2, column=2).coordinate
ws2.add_image(img2)
wb.save('test_output.xlsx')
Is there anything I do wrong here?
Thanks alot in advance.
Up until very recently images in existing files were not preserved. You
need >= 2.5.5 for this.