I am looping through every cell in a workbook. For some reason, when openpyxl iterates through a worksheet that contains an image, the image is deleted. How does one fix this?
I am looking for a way to pass over cells that have an image.
I am not in read_only
mode, and do not desire to be, as I am making modifications to the worksheets.
Something like this would be most useful to me:
if cell is image:
pass
The documentation clearly states that this will happen:
[Emphasis mine]
This has to do with the fact that images and charts are not regular cell content and are stored in a separate part of the file. The functionality to write the images is there, but not to read them.
Your options are to wait for the developers to implement that feature, to use a different library, or to contribute a patch yourself.
A more realistic option might be to write the modifications you make to a different file, and then copy the non-image portions back to the original manually.
Ideally, and this seems to be true in your case, you would have the images available from outside the spreadsheet. In that case, you could insert them back in when you write the file.
Yet another potential workaround would be to open the original file as a zip file and extract the images from it (either manually or programatically).