use of org.apache.poi.hssf.record.DimensionsRecord in project poi by apache.
the class TestSheet method testCloneMulBlank_bug46776.
@Test
public void testCloneMulBlank_bug46776() {
Record[] recs = { InternalSheet.createBOF(), new DimensionsRecord(), new RowRecord(1), new MulBlankRecord(1, 3, new short[] { 0x0F, 0x0F, 0x0F }), new RowRecord(2), createWindow2Record(), EOFRecord.instance };
InternalSheet sheet = createSheet(Arrays.asList(recs));
InternalSheet sheet2;
try {
sheet2 = sheet.cloneSheet();
} catch (RuntimeException e) {
if (e.getMessage().equals("The class org.apache.poi.hssf.record.MulBlankRecord needs to define a clone method")) {
throw new AssertionFailedError("Identified bug 46776");
}
throw e;
}
RecordCollector rc = new RecordCollector();
sheet2.visitContainedRecords(rc, 0);
Record[] clonedRecs = rc.getRecords();
// +2 for INDEX and DBCELL
assertEquals(recs.length + 2, clonedRecs.length);
}
use of org.apache.poi.hssf.record.DimensionsRecord in project poi by apache.
the class TestSheet method testSheetDimensions.
@Test
public void testSheetDimensions() throws IOException {
InternalSheet sheet = InternalSheet.createSheet();
DimensionsRecord dimensions = (DimensionsRecord) sheet.findFirstRecordBySid(DimensionsRecord.sid);
assertEquals(0, dimensions.getFirstCol());
assertEquals(0, dimensions.getFirstRow());
// plus pne
assertEquals(1, dimensions.getLastCol());
// plus pne
assertEquals(1, dimensions.getLastRow());
RowRecord rr = new RowRecord(0);
sheet.addRow(rr);
assertEquals(0, dimensions.getFirstCol());
assertEquals(0, dimensions.getFirstRow());
assertEquals(1, dimensions.getLastCol());
assertEquals(1, dimensions.getLastRow());
CellValueRecordInterface cvr;
cvr = new BlankRecord();
cvr.setColumn((short) 0);
cvr.setRow(0);
sheet.addValueRecord(0, cvr);
assertEquals(0, dimensions.getFirstCol());
assertEquals(0, dimensions.getFirstRow());
assertEquals(1, dimensions.getLastCol());
assertEquals(1, dimensions.getLastRow());
cvr = new BlankRecord();
cvr.setColumn((short) 1);
cvr.setRow(0);
sheet.addValueRecord(0, cvr);
assertEquals(0, dimensions.getFirstCol());
assertEquals(0, dimensions.getFirstRow());
//YK: failed until Bugzilla 53414 was fixed
assertEquals(2, dimensions.getLastCol());
assertEquals(1, dimensions.getLastRow());
}
use of org.apache.poi.hssf.record.DimensionsRecord in project poi by apache.
the class TestSheet method testCreateSheet.
@Test
public void testCreateSheet() {
// Check we're adding row and cell aggregates
List<Record> records = new ArrayList<Record>();
records.add(BOFRecord.createSheetBOF());
records.add(new DimensionsRecord());
records.add(createWindow2Record());
records.add(EOFRecord.instance);
InternalSheet sheet = createSheet(records);
Record[] outRecs = getSheetRecords(sheet, 0);
int pos = 0;
assertTrue(outRecs[pos++] instanceof BOFRecord);
assertTrue(outRecs[pos++] instanceof IndexRecord);
assertTrue(outRecs[pos++] instanceof DimensionsRecord);
assertTrue(outRecs[pos++] instanceof WindowTwoRecord);
assertTrue(outRecs[pos++] instanceof EOFRecord);
}
use of org.apache.poi.hssf.record.DimensionsRecord in project poi by apache.
the class TestHSSFSheet method protectSheetRecordOrder_bug47363a.
/**
* {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block
* (which should be before {@link DimensionsRecord}).
*/
@Test
public void protectSheetRecordOrder_bug47363a() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
s.protectSheet("secret");
RecordCollector rc = new RecordCollector();
s.getSheet().visitContainedRecords(rc, 0);
Record[] recs = rc.getRecords();
int nRecs = recs.length;
if (recs[nRecs - 2] instanceof PasswordRecord && recs[nRecs - 5] instanceof DimensionsRecord) {
fail("Identified bug 47363a - PASSWORD after DIMENSION");
}
// Check that protection block is together, and before DIMENSION
confirmRecordClass(recs, nRecs - 4, DimensionsRecord.class);
confirmRecordClass(recs, nRecs - 9, ProtectRecord.class);
confirmRecordClass(recs, nRecs - 8, ObjectProtectRecord.class);
confirmRecordClass(recs, nRecs - 7, ScenarioProtectRecord.class);
confirmRecordClass(recs, nRecs - 6, PasswordRecord.class);
wb.close();
}
use of org.apache.poi.hssf.record.DimensionsRecord in project poi by apache.
the class InternalSheet method addRow.
/**
* Adds a row record to the sheet
*
* <P>
* This method is "loc" sensitive. Meaning you need to set LOC to where you
* want it to start searching. If you don't know do this: setLoc(getDimsLoc).
* When adding several rows you can just start at the last one by leaving loc
* at what this sets it to.
*
* @param row the row record to be added
*/
public void addRow(RowRecord row) {
if (log.check(POILogger.DEBUG))
log.log(POILogger.DEBUG, "addRow ");
DimensionsRecord d = _dimensions;
if (row.getRowNumber() >= d.getLastRow()) {
d.setLastRow(row.getRowNumber() + 1);
}
if (row.getRowNumber() < d.getFirstRow()) {
d.setFirstRow(row.getRowNumber());
}
//If the row exists remove it, so that any cells attached to the row are removed
RowRecord existingRow = _rowsAggregate.getRow(row.getRowNumber());
if (existingRow != null) {
_rowsAggregate.removeRow(existingRow);
}
_rowsAggregate.insertRow(row);
if (log.check(POILogger.DEBUG))
log.log(POILogger.DEBUG, "exit addRow");
}
Aggregations