Search in sources :

Example 11 with InternalSheet

use of org.apache.poi.hssf.model.InternalSheet in project poi by apache.

the class TestFeatRecord method testReadFeatRecord.

public void testReadFeatRecord() throws Exception {
    HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
    InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
    FeatRecord fr = null;
    FeatHdrRecord fhr = null;
    assertEquals(1, hssf.getNumberOfSheets());
    // First check it isn't on the Workbook
    int countFR = 0;
    int countFRH = 0;
    for (Record r : wb.getRecords()) {
        if (r instanceof FeatRecord) {
            fr = (FeatRecord) r;
            countFR++;
        } else if (r.getSid() == FeatRecord.sid) {
            fail("FeatRecord SID found but not created correctly!");
        }
        if (r instanceof FeatHdrRecord) {
            countFRH++;
        } else if (r.getSid() == FeatHdrRecord.sid) {
            fail("FeatHdrRecord SID found but not created correctly!");
        }
    }
    assertEquals(0, countFR);
    assertEquals(0, countFRH);
    // Now find it on our sheet
    HSSFSheet s = hssf.getSheetAt(0);
    InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
    for (RecordBase rb : sheet.getRecords()) {
        if (rb instanceof Record) {
            Record r = (Record) rb;
            if (r instanceof FeatRecord) {
                fr = (FeatRecord) r;
                countFR++;
            } else if (r.getSid() == FeatRecord.sid) {
                countFR++;
            }
            if (r instanceof FeatHdrRecord) {
                fhr = (FeatHdrRecord) r;
                countFRH++;
            } else if (r.getSid() == FeatHdrRecord.sid) {
                countFRH++;
            }
        }
    }
    assertEquals(1, countFR);
    assertEquals(1, countFRH);
    assertNotNull(fr);
    assertNotNull(fhr);
    // Now check the contents are as expected
    assertEquals(FeatHdrRecord.SHAREDFEATURES_ISFFEC2, fr.getIsf_sharedFeatureType());
    // Applies to one cell only
    assertEquals(1, fr.getCellRefs().length);
    assertEquals(0, fr.getCellRefs()[0].getFirstRow());
    assertEquals(0, fr.getCellRefs()[0].getLastRow());
    assertEquals(0, fr.getCellRefs()[0].getFirstColumn());
    assertEquals(0, fr.getCellRefs()[0].getLastColumn());
    // More checking of shared features stuff
    assertEquals(4, fr.getCbFeatData());
    assertEquals(4, fr.getSharedFeature().getDataSize());
    assertEquals(FeatFormulaErr2.class, fr.getSharedFeature().getClass());
    FeatFormulaErr2 fferr2 = (FeatFormulaErr2) fr.getSharedFeature();
    assertEquals(0x04, fferr2._getRawErrorCheckValue());
    assertFalse(fferr2.getCheckCalculationErrors());
    assertFalse(fferr2.getCheckDateTimeFormats());
    assertFalse(fferr2.getCheckEmptyCellRef());
    assertFalse(fferr2.getCheckInconsistentFormulas());
    assertFalse(fferr2.getCheckInconsistentRanges());
    assertTrue(fferr2.getCheckNumbersAsText());
    assertFalse(fferr2.getCheckUnprotectedFormulas());
    assertFalse(fferr2.getPerformDataValidation());
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) FeatFormulaErr2(org.apache.poi.hssf.record.common.FeatFormulaErr2) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 12 with InternalSheet

use of org.apache.poi.hssf.model.InternalSheet in project poi by apache.

the class TestReadWriteChart method testBOFandEOFRecords.

/**
     * In the presence of a chart we need to make sure BOF/EOF records still exist.
     */
@Test
public void testBOFandEOFRecords() throws Exception {
    HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
    HSSFSheet sheet = workbook.getSheetAt(0);
    HSSFRow firstRow = sheet.getRow(0);
    HSSFCell firstCell = firstRow.getCell(0);
    //System.out.println("first assertion for date");
    Calendar calExp = LocaleUtil.getLocaleCalendar(2000, 0, 1, 10, 51, 2);
    Date dateAct = HSSFDateUtil.getJavaDate(firstCell.getNumericCellValue(), false);
    assertEquals(calExp.getTime(), dateAct);
    HSSFRow row = sheet.createRow(15);
    HSSFCell cell = row.createCell(1);
    cell.setCellValue(22);
    InternalSheet newSheet = workbook.getSheetAt(0).getSheet();
    List<RecordBase> records = newSheet.getRecords();
    assertTrue(records.get(0) instanceof BOFRecord);
    assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
    workbook.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) Calendar(java.util.Calendar) BOFRecord(org.apache.poi.hssf.record.BOFRecord) Date(java.util.Date) Test(org.junit.Test)

Example 13 with InternalSheet

use of org.apache.poi.hssf.model.InternalSheet in project poi by apache.

the class TestHSSFCell method testActiveCell.

/**
	 * Tests that the active cell can be correctly read and set
	 */
@Test
public void testActiveCell() throws IOException {
    //read in sample
    HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
    //check initial position
    HSSFSheet umSheet = wb1.getSheetAt(0);
    InternalSheet s = umSheet.getSheet();
    assertEquals("Initial active cell should be in col 0", (short) 0, s.getActiveCellCol());
    assertEquals("Initial active cell should be on row 1", 1, s.getActiveCellRow());
    //modify position through HSSFCell
    HSSFCell cell = umSheet.createRow(3).createCell(2);
    cell.setAsActiveCell();
    assertEquals("After modify, active cell should be in col 2", (short) 2, s.getActiveCellCol());
    assertEquals("After modify, active cell should be on row 3", 3, s.getActiveCellRow());
    //write book to temp file; read and verify that position is serialized
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    umSheet = wb2.getSheetAt(0);
    s = umSheet.getSheet();
    assertEquals("After serialize, active cell should be in col 2", (short) 2, s.getActiveCellCol());
    assertEquals("After serialize, active cell should be on row 3", 3, s.getActiveCellRow());
    wb2.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) Test(org.junit.Test)

Example 14 with InternalSheet

use of org.apache.poi.hssf.model.InternalSheet in project poi by apache.

the class TestHSSFPicture method bsePictureRef.

@SuppressWarnings("unused")
@Test
public void bsePictureRef() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sh = wb.createSheet("Pictures");
    HSSFPatriarch dr = sh.createDrawingPatriarch();
    HSSFClientAnchor anchor = new HSSFClientAnchor();
    InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
    //register a picture
    byte[] data1 = new byte[] { 1, 2, 3 };
    int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
    assertEquals(1, idx1);
    HSSFPicture p1 = dr.createPicture(anchor, idx1);
    EscherBSERecord bse = wb.getWorkbook().getBSERecord(idx1);
    assertEquals(bse.getRef(), 1);
    dr.createPicture(new HSSFClientAnchor(), idx1);
    assertEquals(bse.getRef(), 2);
    HSSFShapeGroup gr = dr.createGroup(new HSSFClientAnchor());
    gr.createPicture(new HSSFChildAnchor(), idx1);
    assertEquals(bse.getRef(), 3);
    wb.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) Test(org.junit.Test)

Aggregations

InternalSheet (org.apache.poi.hssf.model.InternalSheet)14 Test (org.junit.Test)6 AssertionFailedError (junit.framework.AssertionFailedError)5 RecordStream (org.apache.poi.hssf.model.RecordStream)5 RecordCollector (org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector)5 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)3 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)2 NameRecord (org.apache.poi.hssf.record.NameRecord)2 RecordBase (org.apache.poi.hssf.record.RecordBase)2 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 CellValueRecordInterface (org.apache.poi.hssf.record.CellValueRecordInterface)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1 EmbeddedObjectRefSubRecord (org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord)1