Bug report: Worksheet.Pictures.RemoteAt() fails when shape has already been removed (v4.8.0.0)

In Aspose.Cells for .Net v 4.7.x.x we had code that looked like:

Sub RemovePictures( ByVal ws As Worksheet )
Do While ws.Shapes.Count > 0

ws.Shapes.RemoveAt(0) ’ delete the shapes

Loop


Do While ws.Pictures.Count > 0
ws.Pictures.RemoveAt(0) ’ delete the pictures
Loop
End Sub

This removed any pictures and drawings within the sheet.

In Aspose.Cells for .Net v4.8.0.0 this code fails within the Pictures.RemoveAt method with an IndexOutOfRange error - it appears to be trying to delete the Shape that has already been removed.

A work around for this situation is to remove the Pictures first:

Sub RemovePictures( ByVal ws As Worksheet )

Do While ws.Pictures.Count > 0

ws.Pictures.RemoveAt(0)    ' delete the pictures<br>

Loop


Do While ws.Shapes.Count > 0

ws.Shapes.RemoveAt(0)    ' delete the shapes<br>

Loop

End Sub


Ideally the Pictures.RemoveAt() shouldn’t fail if the shape has already been deleted and a more appropriate error message thrown.

Hi,

Please try the attached version in the thread: http://www.aspose.com/community/forums/204558/bug-report-deletecolumn-no-longer-works-in-4.8.0.0-but-used-to-in-4.7.x.x/showthread.aspx#204558

I have also attached .net1.x compiled version for 32-bit environments. I have tested with it using the attached file and it works fine. The output file is also attached.

Sample code:

Workbook xls = new Aspose.Cells.Workbook();
xls.Open(“f:\test\picremoveat.xlsx”);
Worksheet ws = xls.Worksheets[0];
while (ws.Shapes.Count > 0)
{
ws.Shapes.RemoveAt(0); // delete the shapes
}

while (ws.Pictures.Count > 0)
{
ws.Pictures.RemoveAt(0); // delete the pictures
}

xls.Save(“f:\test\updated_picremoveat.xlsx”, Aspose.Cells.FileFormatType.Excel2007Xlsx);


If you still find the issue, kindly post your template excel file here, we will check it soon.

Thank you.

Thanks for the fix for this one but I’ve found a further issue that’s closely related.

This may have been the case in v4.7.x.x - I’ve not had the chance to check - but if you examine the contents of the XLSX you’ll see that there is an empty drawing1.xml file created along with a .rels file relating to it.

(For anyone reading this who isn’t familiar with XLSX files they are effectively ZIP files containing a folder structure of XML files - you can unzip them with various tools but the best one I’ve found is 7-zip where you can right click them and browse them with the 7-zip open archive content menu option - really great for debugging!)

This is just a hunch but I suspect that you’ve got a list of drawing/shape objects maintained somewhere within the code and even though the referenced picture has been removed the drawing reference has remained. I seem to remember that drawings can be shared across sheets and are actually “held” at the workbook level. I could of course be entirely wrong as you may have implemented it in a different way.

(sorry for having lots of knowledge of the XLSX XML format but I’ve written my own engine to write to XLSX’s before I came across Aspose.Cells :slight_smile: )

cheers,

Gary


Hi Gary.

We appreciate your exploration.

We will get back to you if we can explain you the internal process (for your mentioned issue) a bit when a shape/picture is deleted in the spreadsheet.

Thank you.

Hi Gary,

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells. We have fixed your mentioned issues. Please do let us know if you still face any problem.

Thank You & Best Regards,

Hi there - a quick confirmation that the fix seems to have done the trick.