public void TestPolygonType() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(102, 101); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = wb.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; HSSFPolygon polygon1 = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon1.SetPolygonDrawArea(102, 101); polygon1.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); EscherSpRecord spRecord = polygon1.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; spRecord.ShapeType = ((short)77 /**RANDOM**/); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = wb.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(patriarch.Children.Count, 2); Assert.IsTrue(patriarch.Children[0] is HSSFPolygon); Assert.IsTrue(patriarch.Children[1] is HSSFPolygon); }
public void TestAddToExistingFile() { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet sh = wb1.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(102, 101); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); HSSFPolygon polygon1 = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon1.SetPolygonDrawArea(103, 104); polygon1.SetPoints(new int[] { 11, 12, 13 }, new int[] { 14, 15, 16 }); HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb1.Close(); sh = wb2.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(patriarch.Children.Count, 2); HSSFPolygon polygon2 = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon2.SetPolygonDrawArea(203, 204); polygon2.SetPoints(new int[] { 21, 22, 23 }, new int[] { 24, 25, 26 }); HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2); wb2.Close(); sh = wb3.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(patriarch.Children.Count, 3); polygon = (HSSFPolygon)patriarch.Children[0]; polygon1 = (HSSFPolygon)patriarch.Children[1]; polygon2 = (HSSFPolygon)patriarch.Children[2]; Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 1, 2, 3 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 4, 5, 6 })); Assert.AreEqual(polygon.DrawAreaHeight, 101); Assert.AreEqual(polygon.DrawAreaWidth, 102); Assert.IsTrue(Arrays.Equals(polygon1.XPoints, new int[] { 11, 12, 13 })); Assert.IsTrue(Arrays.Equals(polygon1.YPoints, new int[] { 14, 15, 16 })); Assert.AreEqual(polygon1.DrawAreaHeight, 104); Assert.AreEqual(polygon1.DrawAreaWidth, 103); Assert.IsTrue(Arrays.Equals(polygon2.XPoints, new int[] { 21, 22, 23 })); Assert.IsTrue(Arrays.Equals(polygon2.YPoints, new int[] { 24, 25, 26 })); Assert.AreEqual(polygon2.DrawAreaHeight, 204); Assert.AreEqual(polygon2.DrawAreaWidth, 203); wb3.Close(); }
public void TestPolygonPoints() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(100, 100); polygon.SetPoints(new int[] { 0, 90, 50, 90 }, new int[] { 5, 5, 44, 88 }); PolygonShape polygonShape = HSSFTestModelHelper.CreatePolygonShape(0, polygon); EscherArrayProperty verticesProp1 = polygon.GetOptRecord().Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; EscherArrayProperty verticesProp2 = ((EscherOptRecord)polygonShape.SpContainer.GetChildById(EscherOptRecord.RECORD_ID)) .Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; Assert.AreEqual(verticesProp1.NumberOfElementsInArray, verticesProp2.NumberOfElementsInArray); Assert.AreEqual(verticesProp1.ToXml(""), verticesProp2.ToXml("")); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 1, 2, 3 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 4, 5, 6 })); polygonShape = HSSFTestModelHelper.CreatePolygonShape(0, polygon); verticesProp1 = polygon.GetOptRecord().Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; verticesProp2 = ((EscherOptRecord)polygonShape.SpContainer.GetChildById(EscherOptRecord.RECORD_ID)) .Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; Assert.AreEqual(verticesProp1.NumberOfElementsInArray, verticesProp2.NumberOfElementsInArray); Assert.AreEqual(verticesProp1.ToXml(""), verticesProp2.ToXml("")); }
public void TestSetGetProperties() { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet sh = wb1.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(102, 101); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 1, 2, 3 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 4, 5, 6 })); Assert.AreEqual(polygon.DrawAreaHeight, 101); Assert.AreEqual(polygon.DrawAreaWidth, 102); HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb1.Close(); sh = wb2.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; polygon = (HSSFPolygon)patriarch.Children[0]; Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 1, 2, 3 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 4, 5, 6 })); Assert.AreEqual(polygon.DrawAreaHeight, 101); Assert.AreEqual(polygon.DrawAreaWidth, 102); polygon.SetPolygonDrawArea(1021, 1011); polygon.SetPoints(new int[] { 11, 21, 31 }, new int[] { 41, 51, 61 }); Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 11, 21, 31 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 41, 51, 61 })); Assert.AreEqual(polygon.DrawAreaHeight, 1011); Assert.AreEqual(polygon.DrawAreaWidth, 1021); HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2); wb2.Close(); sh = wb3.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; polygon = (HSSFPolygon)patriarch.Children[0]; Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 11, 21, 31 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 41, 51, 61 })); Assert.AreEqual(polygon.DrawAreaHeight, 1011); Assert.AreEqual(polygon.DrawAreaWidth, 1021); wb3.Close(); }
public void TestPolygonPoints() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(100, 100); polygon.SetPoints(new int[] { 0, 90, 50, 90 }, new int[] { 5, 5, 44, 88 }); EscherArrayProperty verticesProp1 = polygon.GetOptRecord().Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; String expected = "<EscherArrayProperty id=\"0x8145\" name=\"geometry.vertices\" blipId=\"false\">" + "<Element>[00, 00, 05, 00]</Element>" + "<Element>[5A, 00, 05, 00]</Element>" + "<Element>[32, 00, 2C, 00]</Element>" + "<Element>[5A, 00, 58, 00]</Element>" + "<Element>[00, 00, 05, 00]</Element>" + "</EscherArrayProperty>"; String actual = verticesProp1.ToXml("").Replace("\r", "").Replace("\n", "").Replace("\t", ""); Assert.AreEqual(verticesProp1.NumberOfElementsInArray, 5); Assert.AreEqual(expected, actual); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); Assert.IsTrue(Arrays.Equals(polygon.XPoints, new int[] { 1, 2, 3 })); Assert.IsTrue(Arrays.Equals(polygon.YPoints, new int[] { 4, 5, 6 })); verticesProp1 = polygon.GetOptRecord().Lookup(EscherProperties.GEOMETRY__VERTICES) as EscherArrayProperty; expected = "<EscherArrayProperty id=\"0x8145\" name=\"geometry.vertices\" blipId=\"false\">" + "<Element>[01, 00, 04, 00]</Element>" + "<Element>[02, 00, 05, 00]</Element>" + "<Element>[03, 00, 06, 00]</Element>" + "<Element>[01, 00, 04, 00]</Element>" + "</EscherArrayProperty>"; actual = verticesProp1.ToXml("").Replace("\r", "").Replace("\n", "").Replace("\t", ""); Assert.AreEqual(verticesProp1.NumberOfElementsInArray, 4); Assert.AreEqual(expected, actual); wb.Close(); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(100, 100); polygon.SetPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 }); PolygonShape polygonShape = HSSFTestModelHelper.CreatePolygonShape(1024, polygon); polygon.ShapeId = (1024); Assert.AreEqual(polygon.GetEscherContainer().ChildRecords.Count, 4); Assert.AreEqual(polygonShape.SpContainer.ChildRecords.Count, 4); //sp record byte[] expected = polygonShape.SpContainer.GetChild(0).Serialize(); byte[] actual = polygon.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = polygonShape.SpContainer.GetChild(2).Serialize(); actual = polygon.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = polygonShape.SpContainer.GetChild(3).Serialize(); actual = polygon.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = polygon.GetObjRecord(); ObjRecord objShape = polygonShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(100, 100); polygon.SetPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 }); polygon.ShapeId = (1024); Assert.AreEqual(polygon.GetEscherContainer().ChildRecords.Count, 4); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNi4PrAwQAELEDMxcAAAAU6ZlwQAAAA"); byte[] actual = polygon.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = polygon.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = polygon.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = polygon.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBikGNgYBBMYEADAOAV/ZkeAAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }
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); }