Search in sources :

Example 6 with HSSFClientAnchor

use of org.apache.poi.hssf.usermodel.HSSFClientAnchor 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 7 with HSSFClientAnchor

use of org.apache.poi.hssf.usermodel.HSSFClientAnchor 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 8 with HSSFClientAnchor

use of org.apache.poi.hssf.usermodel.HSSFClientAnchor 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)

Example 9 with HSSFClientAnchor

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

the class TestDrawingShapes method testClearShapesForPatriarch.

@Test
public void testClearShapesForPatriarch() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    patriarch.createSimpleShape(new HSSFClientAnchor());
    patriarch.createSimpleShape(new HSSFClientAnchor());
    patriarch.createCellComment(new HSSFClientAnchor());
    EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
    assertEquals(agg.getShapeToObjMapping().size(), 6);
    assertEquals(agg.getTailRecords().size(), 1);
    assertEquals(patriarch.getChildren().size(), 3);
    patriarch.clear();
    assertEquals(agg.getShapeToObjMapping().size(), 0);
    assertEquals(agg.getTailRecords().size(), 0);
    assertEquals(patriarch.getChildren().size(), 0);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    assertEquals(agg.getShapeToObjMapping().size(), 0);
    assertEquals(agg.getTailRecords().size(), 0);
    assertEquals(patriarch.getChildren().size(), 0);
    wb2.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) 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 10 with HSSFClientAnchor

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

the class TestDrawingShapes method testCorrectOrderInOptRecord.

@Test
public void testCorrectOrderInOptRecord() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
    EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
    String opt1Str = opt.toXml();
    textbox.setFillColor(textbox.getFillColor());
    EscherContainerRecord container = HSSFTestHelper.getEscherContainer(textbox);
    EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
    assertEquals(opt1Str, optRecord.toXml());
    textbox.setLineStyle(textbox.getLineStyle());
    assertEquals(opt1Str, optRecord.toXml());
    textbox.setLineWidth(textbox.getLineWidth());
    assertEquals(opt1Str, optRecord.toXml());
    textbox.setLineStyleColor(textbox.getLineStyleColor());
    assertEquals(opt1Str, optRecord.toXml());
    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) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)19 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)14 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)14 Test (org.junit.Test)13 HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)8 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)6 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)3 HSSFShape (org.apache.poi.hssf.usermodel.HSSFShape)3 HSSFTextbox (org.apache.poi.hssf.usermodel.HSSFTextbox)3 Dimension (java.awt.Dimension)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 HSSFChildAnchor (org.apache.poi.hssf.usermodel.HSSFChildAnchor)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 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1