Search in sources :

Example 1 with HSSFPatriarch

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

the class TestDrawingShapes method checkWorkbookBack.

private void checkWorkbookBack(HSSFWorkbook wb) throws IOException {
    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());
    wbBack.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFAnchor(org.apache.poi.hssf.usermodel.HSSFAnchor) HSSFShape(org.apache.poi.hssf.usermodel.HSSFShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 2 with HSSFPatriarch

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

the class TestDrawingShapes method testShapeContainerImplementsIterable.

@SuppressWarnings("unused")
@Test
public void testShapeContainerImplementsIterable() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    patriarch.createSimpleShape(new HSSFClientAnchor());
    patriarch.createSimpleShape(new HSSFClientAnchor());
    int i = 2;
    for (HSSFShape shape : patriarch) {
        i--;
    }
    assertEquals(i, 0);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFShape(org.apache.poi.hssf.usermodel.HSSFShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 3 with HSSFPatriarch

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

the class TestDrawingShapes method testReadExistingImage.

@Test
public void testReadExistingImage() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
    HSSFSheet sheet = wb.getSheet("pictures");
    HSSFPatriarch drawing = sheet.getDrawingPatriarch();
    assertEquals(1, drawing.getChildren().size());
    HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0);
    assertEquals(picture.getPictureIndex(), 2);
    assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
    assertEquals(picture.getFillColor(), 0x5DC943);
    assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
    assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
    assertEquals(picture.isNoFill(), false);
    picture.setPictureIndex(2);
    assertEquals(picture.getPictureIndex(), 2);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFPicture(org.apache.poi.hssf.usermodel.HSSFPicture) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 4 with HSSFPatriarch

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

the class TestDrawingShapes method testTextForSimpleShape.

@Test
public void testTextForSimpleShape() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());
    shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
    EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
    assertEquals(agg.getShapeToObjMapping().size(), 2);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
    agg = HSSFTestHelper.getEscherAggregate(patriarch);
    assertEquals(agg.getShapeToObjMapping().size(), 2);
    shape.setString(new HSSFRichTextString("string1"));
    assertEquals(shape.getString().getString(), "string1");
    assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
    assertEquals(agg.getShapeToObjMapping().size(), 2);
    HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
    wb2.close();
    HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3);
    wb3.close();
    sheet = wb4.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
    assertNotNull(HSSFTestHelper.getTextObjRecord(shape));
    assertEquals(shape.getString().getString(), "string1");
    assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
    assertEquals(agg.getShapeToObjMapping().size(), 2);
    wb4.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) 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)

Example 5 with HSSFPatriarch

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

the class TestDrawingShapes method testOpt.

@Test
public void testOpt() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    // create a sheet with a text box
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
    EscherOptRecord opt1 = HSSFTestHelper.getOptRecord(textbox);
    EscherOptRecord opt2 = HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID);
    assertSame(opt1, opt2);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFTextbox(org.apache.poi.hssf.usermodel.HSSFTextbox) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)20 Test (org.junit.Test)16 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)14 HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)8 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)6 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)5 HSSFShape (org.apache.poi.hssf.usermodel.HSSFShape)3 HSSFTextbox (org.apache.poi.hssf.usermodel.HSSFTextbox)3 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 HSSFComment (org.apache.poi.hssf.usermodel.HSSFComment)2 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)2 HSSFPicture (org.apache.poi.hssf.usermodel.HSSFPicture)2 HSSFShapeGroup (org.apache.poi.hssf.usermodel.HSSFShapeGroup)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1