Deleting shape from a group

Hi,

I have a requirement to delete a shape from a group of shapes

for example

foreach (var item in group.GetGroupedShapes())
{
if (string.CompareOrdinal(item.Name, shapeToBeDeleted) == 0)
{
//will this work for shapes which are a part of a group and also which are not?
m_worksheet.Shapes.Remove(item);

// the method summary for DeleteShape says that shapes in groups will not be deleted
m_worksheet.Shapes.DeleteShape(item);

}
}

Could you please let me know how to go about this?

Thanks

Hi Yashali,


Thank you for contacting Aspose support.

We would recommend you to use the Shapes.RemoveAt method that allows to delete a shape regardless of the fact that the given shape is grouped. Please check the following piece of code for better elaboration and attached spreadsheets for your reference.

C#

var _workbook = new Workbook(“D:/temp/input.xls”);
var _worksheet = _workbook.Worksheets[“Sheet1”];
var _shapes = _worksheet.Shapes;
for(int _index = 0; _index <= _shapes.Count; _index++)
{
if(_shapes[_index].Name == “Oval 2”)
{
_shapes.RemoveAt(_index);
break;
}
}
_workbook.Save(“D:/output.xls”);