use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class RecordOrderer method findDataValidationTableInsertPos.
/**
* Finds the index where the sheet validations header record should be inserted
* @param records the records for this sheet
*
* + WINDOW2
* o SCL
* o PANE
* oo SELECTION
* o STANDARDWIDTH
* oo MERGEDCELLS
* o LABELRANGES
* o PHONETICPR
* o Conditional Formatting Table
* o Hyperlink Table
* o Data Validity Table
* o SHEETLAYOUT
* o SHEETPROTECTION
* o RANGEPROTECTION
* + EOF
*/
private static int findDataValidationTableInsertPos(List<RecordBase> records) {
int i = records.size() - 1;
if (!(records.get(i) instanceof EOFRecord)) {
throw new IllegalStateException("Last sheet record should be EOFRecord");
}
while (i > 0) {
i--;
RecordBase rb = records.get(i);
if (isDVTPriorRecord(rb)) {
Record nextRec = (Record) records.get(i + 1);
if (!isDVTSubsequentRecord(nextRec.getSid())) {
throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName() + ") found after (" + rb.getClass().getName() + ")");
}
return i + 1;
}
Record rec = (Record) rb;
if (!isDVTSubsequentRecord(rec.getSid())) {
throw new IllegalStateException("Unexpected (" + rec.getClass().getName() + ") while looking for DV Table insert pos");
}
}
return 0;
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class ValueRecordsAggregate method visitCellsForRow.
public void visitCellsForRow(int rowIndex, RecordVisitor rv) {
CellValueRecordInterface[] rowCells = records[rowIndex];
if (rowCells == null) {
throw new IllegalArgumentException("Row [" + rowIndex + "] is empty");
}
for (int i = 0; i < rowCells.length; i++) {
RecordBase cvr = (RecordBase) rowCells[i];
if (cvr == null) {
continue;
}
int nBlank = countBlanks(rowCells, i);
if (nBlank > 1) {
rv.visitRecord(createMBR(rowCells, i, nBlank));
i += nBlank - 1;
} else if (cvr instanceof RecordAggregate) {
RecordAggregate agg = (RecordAggregate) cvr;
agg.visitContainedRecords(rv);
} else {
rv.visitRecord((Record) cvr);
}
}
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class ValueRecordsAggregate method getRowSerializedSize.
private static int getRowSerializedSize(CellValueRecordInterface[] rowCells) {
if (rowCells == null) {
return 0;
}
int result = 0;
for (int i = 0; i < rowCells.length; i++) {
RecordBase cvr = (RecordBase) rowCells[i];
if (cvr == null) {
continue;
}
int nBlank = countBlanks(rowCells, i);
if (nBlank > 1) {
result += (10 + 2 * nBlank);
i += nBlank - 1;
} else {
result += cvr.getRecordSize();
}
}
return result;
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestSheet method confirmAggregatedRecords.
private void confirmAggregatedRecords(List<Record> recordStream) {
InternalSheet sheet = InternalSheet.createSheet();
sheet.getRecords().clear();
sheet.getRecords().addAll(recordStream);
List<RecordBase> sheetRecords = sheet.getRecords();
DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
sheet.aggregateDrawingRecords(drawingManager, false);
assertEquals(4, sheetRecords.size());
assertEquals(BOFRecord.sid, ((Record) sheetRecords.get(0)).getSid());
assertEquals(EscherAggregate.sid, ((Record) sheetRecords.get(1)).getSid());
assertEquals(WindowTwoRecord.sid, ((Record) sheetRecords.get(2)).getSid());
assertEquals(EOFRecord.sid, ((Record) sheetRecords.get(3)).getSid());
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestHSSFWorkbook method sheetSerializeSizeMismatch_bug45066.
/**
* If Sheet.getSize() returns a different result to Sheet.serialize(), this will cause the BOF
* records to be written with invalid offset indexes. Excel does not like this, and such
* errors are particularly hard to track down. This test ensures that HSSFWorkbook throws
* a specific exception as soon as the situation is detected. See bugzilla 45066
* @throws IOException
*/
@Test
public void sheetSerializeSizeMismatch_bug45066() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
List<RecordBase> sheetRecords = sheet.getRecords();
// one way (of many) to cause the discrepancy is with a badly behaved record:
sheetRecords.add(new BadlyBehavedRecord());
// There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
try {
wb.getBytes();
fail("Identified bug 45066 a");
} catch (IllegalStateException e) {
// Expected badly behaved sheet record to cause exception
assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
}
wb.close();
}
Aggregations