public void testBug45312() throws Exception { HSSFWorkbook wb = new HSSFWorkbook(); try { HSSFSheet sheet = wb.createSheet(); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 1, 1, 0, 0, (short) 1, 1, 512, 100); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 1, 1, 512, 0, (short) 1, 1, 1024, 100); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setFlipVertical(true); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 2, 2, 0, 0, (short) 2, 2, 512, 100); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 2, 2, 0, 100, (short) 2, 2, 512, 200); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setFlipHorizontal(true); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } /*OutputStream stream = new FileOutputStream("/tmp/45312.xls"); try { wb.write(stream); } finally { stream.close(); }*/ checkWorkbookBack(wb); } finally { wb.close(); } }
private void checkWorkbookBack(HSSFWorkbook wb) { HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb); assertNotNull(wbBack); HSSFSheet sheetBack = wbBack.getSheetAt(0); assertNotNull(sheetBack); HSSFPatriarch patriarchBack = sheetBack.getDrawingPatriarch(); assertNotNull(patriarchBack); List<HSSFShape> children = patriarchBack.getChildren(); assertEquals(4, children.size()); HSSFShape hssfShape = children.get(0); assertTrue(hssfShape instanceof HSSFSimpleShape); HSSFAnchor anchor = hssfShape.getAnchor(); assertTrue(anchor instanceof HSSFClientAnchor); assertEquals(0, anchor.getDx1()); assertEquals(512, anchor.getDx2()); assertEquals(0, anchor.getDy1()); assertEquals(100, anchor.getDy2()); HSSFClientAnchor cAnchor = (HSSFClientAnchor) anchor; assertEquals(1, cAnchor.getCol1()); assertEquals(1, cAnchor.getCol2()); assertEquals(1, cAnchor.getRow1()); assertEquals(1, cAnchor.getRow2()); hssfShape = children.get(1); assertTrue(hssfShape instanceof HSSFSimpleShape); anchor = hssfShape.getAnchor(); assertTrue(anchor instanceof HSSFClientAnchor); assertEquals(512, anchor.getDx1()); assertEquals(1024, anchor.getDx2()); assertEquals(0, anchor.getDy1()); assertEquals(100, anchor.getDy2()); cAnchor = (HSSFClientAnchor) anchor; assertEquals(1, cAnchor.getCol1()); assertEquals(1, cAnchor.getCol2()); assertEquals(1, cAnchor.getRow1()); assertEquals(1, cAnchor.getRow2()); hssfShape = children.get(2); assertTrue(hssfShape instanceof HSSFSimpleShape); anchor = hssfShape.getAnchor(); assertTrue(anchor instanceof HSSFClientAnchor); assertEquals(0, anchor.getDx1()); assertEquals(512, anchor.getDx2()); assertEquals(0, anchor.getDy1()); assertEquals(100, anchor.getDy2()); cAnchor = (HSSFClientAnchor) anchor; assertEquals(2, cAnchor.getCol1()); assertEquals(2, cAnchor.getCol2()); assertEquals(2, cAnchor.getRow1()); assertEquals(2, cAnchor.getRow2()); hssfShape = children.get(3); assertTrue(hssfShape instanceof HSSFSimpleShape); anchor = hssfShape.getAnchor(); assertTrue(anchor instanceof HSSFClientAnchor); assertEquals(0, anchor.getDx1()); assertEquals(512, anchor.getDx2()); assertEquals(100, anchor.getDy1()); assertEquals(200, anchor.getDy2()); cAnchor = (HSSFClientAnchor) anchor; assertEquals(2, cAnchor.getCol1()); assertEquals(2, cAnchor.getCol2()); assertEquals(2, cAnchor.getRow1()); assertEquals(2, cAnchor.getRow2()); }
/** * create a rectangle, save the workbook, read back and verify that all shape properties are there */ public void testReadWriteRectangle() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFPatriarch drawing = sheet.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short) 4, 4); anchor.setAnchorType(2); assertEquals(anchor.getAnchorType(), 2); HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor); rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); rectangle.setLineWidth(10000); rectangle.setFillColor(777); assertEquals(rectangle.getFillColor(), 777); assertEquals(10000, rectangle.getLineWidth()); rectangle.setLineStyle(10); assertEquals(10, rectangle.getLineStyle()); assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_SQUARE); rectangle.setLineStyleColor(1111); rectangle.setNoFill(true); rectangle.setWrapText(HSSFSimpleShape.WRAP_NONE); rectangle.setString(new HSSFRichTextString("teeeest")); assertEquals(rectangle.getLineStyleColor(), 1111); assertEquals( ((EscherSimpleProperty) ((EscherOptRecord) HSSFTestHelper.getEscherContainer(rectangle) .getChildById(EscherOptRecord.RECORD_ID)) .lookup(EscherProperties.TEXT__TEXTID)) .getPropertyValue(), "teeeest".hashCode()); assertEquals(rectangle.isNoFill(), true); assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE); assertEquals(rectangle.getString().getString(), "teeeest"); wb = HSSFTestDataSamples.writeOutAndReadBack(wb); sheet = wb.getSheetAt(0); drawing = sheet.getDrawingPatriarch(); assertEquals(1, drawing.getChildren().size()); HSSFSimpleShape rectangle2 = (HSSFSimpleShape) drawing.getChildren().get(0); assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType()); assertEquals(10000, rectangle2.getLineWidth()); assertEquals(10, rectangle2.getLineStyle()); assertEquals(anchor, rectangle2.getAnchor()); assertEquals(rectangle2.getLineStyleColor(), 1111); assertEquals(rectangle2.getFillColor(), 777); assertEquals(rectangle2.isNoFill(), true); assertEquals(rectangle2.getString().getString(), "teeeest"); assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE); rectangle2.setFillColor(3333); rectangle2.setLineStyle(9); rectangle2.setLineStyleColor(4444); rectangle2.setNoFill(false); rectangle2.setLineWidth(77); rectangle2.getAnchor().setDx1(2); rectangle2.getAnchor().setDx2(3); rectangle2.getAnchor().setDy1(4); rectangle2.getAnchor().setDy2(5); rectangle.setWrapText(HSSFSimpleShape.WRAP_BY_POINTS); rectangle2.setString(new HSSFRichTextString("test22")); wb = HSSFTestDataSamples.writeOutAndReadBack(wb); sheet = wb.getSheetAt(0); drawing = sheet.getDrawingPatriarch(); assertEquals(1, drawing.getChildren().size()); rectangle2 = (HSSFSimpleShape) drawing.getChildren().get(0); assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType()); assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_BY_POINTS); assertEquals(77, rectangle2.getLineWidth()); assertEquals(9, rectangle2.getLineStyle()); assertEquals(rectangle2.getLineStyleColor(), 4444); assertEquals(rectangle2.getFillColor(), 3333); assertEquals(rectangle2.getAnchor().getDx1(), 2); assertEquals(rectangle2.getAnchor().getDx2(), 3); assertEquals(rectangle2.getAnchor().getDy1(), 4); assertEquals(rectangle2.getAnchor().getDy2(), 5); assertEquals(rectangle2.isNoFill(), false); assertEquals(rectangle2.getString().getString(), "test22"); HSSFSimpleShape rect3 = drawing.createSimpleShape(new HSSFClientAnchor()); rect3.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); wb = HSSFTestDataSamples.writeOutAndReadBack(wb); drawing = wb.getSheetAt(0).getDrawingPatriarch(); assertEquals(drawing.getChildren().size(), 2); }