How to delete picture / shape from excel sheet to avoid the error xlwings.ShapeAlreadyExists

Viewed 24

I am sending a matplotlib chart into excel as a picture and giving it a name.

However, if the code is run again, the picture would not be updated and the following error is raised: xlwings.ShapeAlreadyExists

here is a snippet of the code:

caller.sheet.pictures.add(a, 
                         top=caller.offset(row_offset=1).top, 
                         left=caller.left,
                         name="memberss", update=False) 

I realise that if I change update to True, this would work but the shape would retain its dimensions and not be updated.

What I want to do is to actually delete the existing shape and insert a new one in its place.

Is there a Pictures.delete attribute which takes the name of the shape and delete it?

I see there is Picture.delete but I dont seem to get it to work

Picture.delete

https://docs.xlwings.org/en/stable/api.html#xlwings.main.Pictures.add

0 Answers
Related