Search in sources :

Example 6 with HSSFSimpleShape

use of org.apache.poi.hssf.usermodel.HSSFSimpleShape in project poi by apache.

the class TestDrawingShapes method testReadExistingRectangle.

/* assert shape properties when reading shapes from a existing workbook */
@Test
public void testReadExistingRectangle() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
    HSSFSheet sheet = wb.getSheet("rectangles");
    HSSFPatriarch drawing = sheet.getDrawingPatriarch();
    assertEquals(1, drawing.getChildren().size());
    HSSFSimpleShape shape = (HSSFSimpleShape) drawing.getChildren().get(0);
    assertEquals(shape.isNoFill(), false);
    assertEquals(shape.getLineStyle(), HSSFShape.LINESTYLE_DASHDOTGEL);
    assertEquals(shape.getLineStyleColor(), 0x616161);
    assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D);
    assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2);
    assertEquals(shape.getString().getString(), "POItest");
    assertEquals(shape.getRotationDegree(), 27);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 7 with HSSFSimpleShape

use of org.apache.poi.hssf.usermodel.HSSFSimpleShape in project poi by apache.

the class TestDrawingShapes method testShapeFlip.

@Test
public void testShapeFlip() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor());
    rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
    assertEquals(rectangle.isFlipVertical(), false);
    assertEquals(rectangle.isFlipHorizontal(), false);
    rectangle.setFlipVertical(true);
    assertEquals(rectangle.isFlipVertical(), true);
    rectangle.setFlipHorizontal(true);
    assertEquals(rectangle.isFlipHorizontal(), true);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);
    assertEquals(rectangle.isFlipHorizontal(), true);
    rectangle.setFlipHorizontal(false);
    assertEquals(rectangle.isFlipHorizontal(), false);
    assertEquals(rectangle.isFlipVertical(), true);
    rectangle.setFlipVertical(false);
    assertEquals(rectangle.isFlipVertical(), false);
    HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
    wb2.close();
    sheet = wb3.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);
    assertEquals(rectangle.isFlipVertical(), false);
    assertEquals(rectangle.isFlipHorizontal(), false);
    wb3.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 8 with HSSFSimpleShape

use of org.apache.poi.hssf.usermodel.HSSFSimpleShape in project poi by apache.

the class TestDrawingShapes method testBug45312.

@Test
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();
    }
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 9 with HSSFSimpleShape

use of org.apache.poi.hssf.usermodel.HSSFSimpleShape in project poi by apache.

the class TestDrawingShapes method testRotation.

@Test
public void testRotation() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor(0, 0, 100, 100, (short) 0, 0, (short) 5, 5));
    rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
    assertEquals(rectangle.getRotationDegree(), 0);
    rectangle.setRotationDegree((short) 45);
    assertEquals(rectangle.getRotationDegree(), 45);
    rectangle.setFlipHorizontal(true);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);
    assertEquals(rectangle.getRotationDegree(), 45);
    rectangle.setRotationDegree((short) 30);
    assertEquals(rectangle.getRotationDegree(), 30);
    patriarch.setCoordinates(0, 0, 10, 10);
    rectangle.setString(new HSSFRichTextString("1234"));
    wb2.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)9 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)8 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)8 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)8 Test (org.junit.Test)8 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)3 HSSFShape (org.apache.poi.hssf.usermodel.HSSFShape)2 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)1 HSSFAnchor (org.apache.poi.hssf.usermodel.HSSFAnchor)1 HSSFChildAnchor (org.apache.poi.hssf.usermodel.HSSFChildAnchor)1 HSSFComment (org.apache.poi.hssf.usermodel.HSSFComment)1 HSSFPicture (org.apache.poi.hssf.usermodel.HSSFPicture)1 HSSFPolygon (org.apache.poi.hssf.usermodel.HSSFPolygon)1 HSSFShapeGroup (org.apache.poi.hssf.usermodel.HSSFShapeGroup)1 HSSFTextbox (org.apache.poi.hssf.usermodel.HSSFTextbox)1