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());
}
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();
}
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();
}
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();
}
Aggregations