Search in sources :

Example 76 with HSSFWorkbook

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

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

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

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

the class TestDrawingShapes method testAllocateNewIds.

/**
     * Test get new id for shapes from existing file
     * File already have for 1 shape on each sheet, because document must contain EscherDgRecord for each sheet
     */
@Test
public void testAllocateNewIds() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("empty.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
    /**
         * 2048 - main SpContainer id
         * 2049 - existing shape id
         */
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2050);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2051);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2052);
    sheet = wb.getSheetAt(1);
    patriarch = sheet.getDrawingPatriarch();
    /**
         * 3072 - main SpContainer id
         * 3073 - existing shape id
         */
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3074);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3075);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3076);
    sheet = wb.getSheetAt(2);
    patriarch = sheet.getDrawingPatriarch();
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1026);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1027);
    assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1028);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 80 with HSSFWorkbook

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

the class TestDrawingShapes method testDgRecordNumShapes.

@Test
public void testDgRecordNumShapes() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    EscherAggregate aggregate = HSSFTestHelper.getEscherAggregate(patriarch);
    EscherDgRecord dgRecord = (EscherDgRecord) aggregate.getEscherRecord(0).getChild(0);
    assertEquals(dgRecord.getNumShapes(), 1);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)518 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)187 Test (org.junit.Test)172 Workbook (org.apache.poi.ss.usermodel.Workbook)144 Sheet (org.apache.poi.ss.usermodel.Sheet)128 Row (org.apache.poi.ss.usermodel.Row)102 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)100 Cell (org.apache.poi.ss.usermodel.Cell)96 FileOutputStream (java.io.FileOutputStream)93 IOException (java.io.IOException)91 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)77 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)69 FileInputStream (java.io.FileInputStream)59 File (java.io.File)58 ArrayList (java.util.ArrayList)52 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)38 InputStream (java.io.InputStream)28 OutputStream (java.io.OutputStream)28 CellStyle (org.apache.poi.ss.usermodel.CellStyle)28 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)26