public void TestRemoveShapes() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor()); rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE; int idx = wb.AddPicture(new byte[] { 1, 2, 3 }, PictureType.JPEG); patriarch.CreatePicture(new HSSFClientAnchor(), idx); patriarch.CreateCellComment(new HSSFClientAnchor()); HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPoints(new int[] { 1, 2 }, new int[] { 2, 3 }); patriarch.CreateTextbox(new HSSFClientAnchor()); HSSFShapeGroup group = patriarch.CreateGroup(new HSSFClientAnchor()); group.CreateTextbox(new HSSFChildAnchor()); group.CreatePicture(new HSSFChildAnchor(), idx); Assert.AreEqual(patriarch.Children.Count, 6); Assert.AreEqual(group.Children.Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 6); group = (HSSFShapeGroup)patriarch.Children[5]; group.RemoveShape(group.Children[0]); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); group = (HSSFShapeGroup)patriarch.Children[(5)]; patriarch.RemoveShape(group); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 5); HSSFShape shape = patriarch.Children[0]; patriarch.RemoveShape(shape); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 4); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 4); HSSFPicture picture = (HSSFPicture)patriarch.Children[0]; patriarch.RemoveShape(picture); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 3); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 3); HSSFComment comment = (HSSFComment)patriarch.Children[0]; patriarch.RemoveShape(comment); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 2); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 2); polygon = (HSSFPolygon)patriarch.Children[0]; patriarch.RemoveShape(polygon); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 1); HSSFTextbox textbox = (HSSFTextbox)patriarch.Children[0]; patriarch.RemoveShape(textbox); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 0); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 0); }