use of org.apache.poi.hssf.record.Record in project poi by apache.
the class InternalWorkbook method findDrawingGroup.
/**
* Finds the primary drawing group, if one already exists
*
* @return the primary drawing group
*/
public DrawingManager2 findDrawingGroup() {
if (drawingManager != null) {
// We already have it!
return drawingManager;
}
// Need to find a DrawingGroupRecord that contains a EscherDggRecord
for (Record r : records) {
if (!(r instanceof DrawingGroupRecord)) {
continue;
}
DrawingGroupRecord dg = (DrawingGroupRecord) r;
dg.processChildRecords();
drawingManager = findDrawingManager(dg, escherBSERecords);
if (drawingManager != null) {
return drawingManager;
}
}
// TODO: we've already scanned the records, why should this work any better now?
// Look for the DrawingGroup record
DrawingGroupRecord dg = (DrawingGroupRecord) findFirstRecordBySid(DrawingGroupRecord.sid);
drawingManager = findDrawingManager(dg, escherBSERecords);
return drawingManager;
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class InternalWorkbook method createWorkbook.
/**
* Creates an empty workbook object with three blank sheets and all the empty
* fields. Use this to create a workbook from scratch.
*
* @return an empty workbook object
*/
public static InternalWorkbook createWorkbook() {
LOG.log(DEBUG, "creating new workbook from scratch");
InternalWorkbook retval = new InternalWorkbook();
List<Record> records = new ArrayList<Record>(30);
retval.records.setRecords(records);
List<FormatRecord> formats = retval.formats;
records.add(createBOF());
records.add(new InterfaceHdrRecord(CODEPAGE));
records.add(createMMS());
records.add(InterfaceEndRecord.instance);
records.add(createWriteAccess());
records.add(createCodepage());
records.add(createDSF());
records.add(createTabId());
retval.records.setTabpos(records.size() - 1);
records.add(createFnGroupCount());
records.add(createWindowProtect());
records.add(createProtect());
retval.records.setProtpos(records.size() - 1);
records.add(createPassword());
records.add(createProtectionRev4());
records.add(createPasswordRev4());
retval.windowOne = createWindowOne();
records.add(retval.windowOne);
records.add(createBackup());
retval.records.setBackuppos(records.size() - 1);
records.add(createHideObj());
records.add(createDateWindow1904());
records.add(createPrecision());
records.add(createRefreshAll());
records.add(createBookBool());
records.add(createFont());
records.add(createFont());
records.add(createFont());
records.add(createFont());
// last font record position
retval.records.setFontpos(records.size() - 1);
retval.numfonts = 4;
// set up format records
for (int i = 0; i <= 7; i++) {
FormatRecord rec = createFormat(i);
retval.maxformatid = retval.maxformatid >= rec.getIndexCode() ? retval.maxformatid : rec.getIndexCode();
formats.add(rec);
records.add(rec);
}
for (int k = 0; k < 21; k++) {
records.add(InternalWorkbook.createExtendedFormat(k));
retval.numxfs++;
}
retval.records.setXfpos(records.size() - 1);
for (int k = 0; k < 6; k++) {
records.add(InternalWorkbook.createStyle(k));
}
records.add(InternalWorkbook.createUseSelFS());
// now just do 1
int nBoundSheets = 1;
for (int k = 0; k < nBoundSheets; k++) {
BoundSheetRecord bsr = createBoundSheet(k);
records.add(bsr);
retval.boundsheets.add(bsr);
retval.records.setBspos(records.size() - 1);
}
records.add(InternalWorkbook.createCountry());
for (int k = 0; k < nBoundSheets; k++) {
retval.getOrCreateLinkTable().checkExternSheet(k);
}
retval.sst = new SSTRecord();
records.add(retval.sst);
records.add(InternalWorkbook.createExtendedSST());
records.add(EOFRecord.instance);
LOG.log(DEBUG, "exit create new workbook from scratch");
return retval;
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class InternalWorkbook method serialize.
/**
* Serializes all records int the worksheet section into a big byte array. Use
* this to write the Workbook out.
* @param offset of the data to be written
* @param data array of bytes to write this to
* @return the length of serialized bytes
*/
public int serialize(int offset, byte[] data) {
LOG.log(DEBUG, "Serializing Workbook with offsets");
int pos = 0;
SSTRecord lSST = null;
int sstPos = 0;
boolean wroteBoundSheets = false;
for (Record record : records) {
int len = 0;
if (record instanceof SSTRecord) {
lSST = (SSTRecord) record;
sstPos = pos;
}
if (record.getSid() == ExtSSTRecord.sid && lSST != null) {
record = lSST.createExtSSTRecord(sstPos + offset);
}
if (record instanceof BoundSheetRecord) {
if (!wroteBoundSheets) {
for (BoundSheetRecord bsr : boundsheets) {
len += bsr.serialize(pos + offset + len, data);
}
wroteBoundSheets = true;
}
} else {
len = record.serialize(pos + offset, data);
}
pos += len;
}
LOG.log(DEBUG, "Exiting serialize workbook");
return pos;
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class InternalSheet method findFirstRecordLocBySid.
/**
* Finds the first occurrence of a record matching a particular sid and
* returns it's position.
* @param sid the sid to search for
* @return the record position of the matching record or -1 if no match
* is made.
*/
public int findFirstRecordLocBySid(short sid) {
// TODO - remove this method
int max = _records.size();
for (int i = 0; i < max; i++) {
Object rb = _records.get(i);
if (!(rb instanceof Record)) {
continue;
}
Record record = (Record) rb;
if (record.getSid() == sid) {
return i;
}
}
return -1;
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class EFBiffViewer method run.
public void run() throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
try {
InputStream din = BiffViewer.getPOIFSInputStream(fs);
try {
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(new HSSFListener() {
public void processRecord(Record rec) {
System.out.println(rec);
}
});
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
} finally {
din.close();
}
} finally {
fs.close();
}
}
Aggregations