use of org.apache.poi.hssf.record.Record in project poi by apache.
the class BiffViewer method createRecords.
/**
* Create an array of records from an input stream
*
* @param is the InputStream from which the records will be obtained
* @param ps the PrintWriter to output the record data
* @param recListener the record listener to notify about read records
* @param dumpInterpretedRecords if {@code true}, the read records will be written to the PrintWriter
*
* @return an array of Records created from the InputStream
* @exception org.apache.poi.util.RecordFormatException on error processing the InputStream
*/
public static Record[] createRecords(InputStream is, PrintWriter ps, BiffRecordListener recListener, boolean dumpInterpretedRecords) throws org.apache.poi.util.RecordFormatException {
List<Record> temp = new ArrayList<Record>();
RecordInputStream recStream = new RecordInputStream(is);
while (true) {
boolean hasNext;
try {
hasNext = recStream.hasNextRecord();
} catch (LeftoverDataException e) {
logger.log(POILogger.ERROR, "Discarding " + recStream.remaining() + " bytes and continuing", e);
recStream.readRemainder();
hasNext = recStream.hasNextRecord();
}
if (!hasNext) {
break;
}
recStream.nextRecord();
if (recStream.getSid() == 0) {
continue;
}
Record record;
if (dumpInterpretedRecords) {
record = createRecord(recStream);
if (record.getSid() == ContinueRecord.sid) {
continue;
}
temp.add(record);
for (String header : recListener.getRecentHeaders()) {
ps.println(header);
}
ps.print(record);
} else {
recStream.readRemainder();
}
ps.println();
}
Record[] result = new Record[temp.size()];
temp.toArray(result);
return result;
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class EventWorkbookBuilder method createStubWorkbook.
/**
* Creates a stub Workbook from the supplied records,
* suitable for use with the {@link HSSFFormulaParser}
* @param externs The ExternSheetRecords in your file
* @param bounds The BoundSheetRecords in your file
* @param sst The SSTRecord in your file.
* @return A stub Workbook suitable for use with {@link HSSFFormulaParser}
*/
public static InternalWorkbook createStubWorkbook(ExternSheetRecord[] externs, BoundSheetRecord[] bounds, SSTRecord sst) {
List<Record> wbRecords = new ArrayList<Record>();
// Core Workbook records go first
if (bounds != null) {
for (BoundSheetRecord bound : bounds) {
wbRecords.add(bound);
}
}
if (sst != null) {
wbRecords.add(sst);
}
// preceded by a SupBookRecord
if (externs != null) {
wbRecords.add(SupBookRecord.createInternalReferences((short) externs.length));
for (ExternSheetRecord extern : externs) {
wbRecords.add(extern);
}
}
// Finally we need an EoF record
wbRecords.add(EOFRecord.instance);
return InternalWorkbook.createWorkbook(wbRecords);
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class InternalWorkbook method fixTabIdRecord.
/**
* make the tabid record look like the current situation.
*/
private void fixTabIdRecord() {
Record rec = records.get(records.getTabpos());
// we use the same check on Tabpos as done in other places
if (records.getTabpos() <= 0) {
return;
}
TabIdRecord tir = (TabIdRecord) rec;
short[] tia = new short[boundsheets.size()];
for (short k = 0; k < tia.length; k++) {
tia[k] = k;
}
tir.setTabIdArray(tia);
}
use of org.apache.poi.hssf.record.Record 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.Record in project poi by apache.
the class RecordOrderer method findInsertPosForNewMergedRecordTable.
private static int findInsertPosForNewMergedRecordTable(List<RecordBase> records) {
for (int i = records.size() - 2; i >= 0; i--) {
// -2 to skip EOF record
Object rb = records.get(i);
if (!(rb instanceof Record)) {
// even PageSettingsBlock (which doesn't normally appear after 'View Settings')
continue;
}
Record rec = (Record) rb;
switch(rec.getSid()) {
// 'View Settings' (4 records)
case WindowTwoRecord.sid:
case SCLRecord.sid:
case PaneRecord.sid:
case SelectionRecord.sid:
case UnknownRecord.STANDARDWIDTH_0099:
return i + 1;
}
}
throw new RuntimeException("Did not find Window2 record");
}
Aggregations