use of org.apache.poi.hssf.record.FormatRecord in project poi by apache.
the class InternalWorkbook method createWorkbook.
/**
* read support for low level
* API. Pass in an array of Record objects, A Workbook
* object is constructed and passed back with all of its initialization set
* to the passed in records and references to those records held. Unlike Sheet
* workbook does not use an offset (its assumed to be 0) since its first in a file.
* If you need an offset then construct a new array with a 0 offset or write your
* own ;-p.
*
* @param recs an array of Record objects
* @return Workbook object
*/
public static InternalWorkbook createWorkbook(List<Record> recs) {
LOG.log(DEBUG, "Workbook (readfile) created with reclen=", recs.size());
InternalWorkbook retval = new InternalWorkbook();
List<Record> records = new ArrayList<Record>(recs.size() / 3);
retval.records.setRecords(records);
boolean eofPassed = false;
for (int k = 0; k < recs.size(); k++) {
Record rec = recs.get(k);
String logObj;
switch(rec.getSid()) {
case EOFRecord.sid:
logObj = "workbook eof";
break;
case BoundSheetRecord.sid:
logObj = "boundsheet";
retval.boundsheets.add((BoundSheetRecord) rec);
retval.records.setBspos(k);
break;
case SSTRecord.sid:
logObj = "sst";
retval.sst = (SSTRecord) rec;
break;
case FontRecord.sid:
logObj = "font";
retval.records.setFontpos(k);
retval.numfonts++;
break;
case ExtendedFormatRecord.sid:
logObj = "XF";
retval.records.setXfpos(k);
retval.numxfs++;
break;
case TabIdRecord.sid:
logObj = "tabid";
retval.records.setTabpos(k);
break;
case ProtectRecord.sid:
logObj = "protect";
retval.records.setProtpos(k);
break;
case BackupRecord.sid:
logObj = "backup";
retval.records.setBackuppos(k);
break;
case ExternSheetRecord.sid:
throw new RecordFormatException("Extern sheet is part of LinkTable");
case NameRecord.sid:
case SupBookRecord.sid:
// LinkTable can start with either of these
LOG.log(DEBUG, "found SupBook record at " + k);
retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
k += retval.linkTable.getRecordCount() - 1;
continue;
case FormatRecord.sid:
logObj = "format";
FormatRecord fr = (FormatRecord) rec;
retval.formats.add(fr);
retval.maxformatid = retval.maxformatid >= fr.getIndexCode() ? retval.maxformatid : fr.getIndexCode();
break;
case DateWindow1904Record.sid:
logObj = "datewindow1904";
retval.uses1904datewindowing = ((DateWindow1904Record) rec).getWindowing() == 1;
break;
case PaletteRecord.sid:
logObj = "palette";
retval.records.setPalettepos(k);
break;
case WindowOneRecord.sid:
logObj = "WindowOneRecord";
retval.windowOne = (WindowOneRecord) rec;
break;
case WriteAccessRecord.sid:
logObj = "WriteAccess";
retval.writeAccess = (WriteAccessRecord) rec;
break;
case WriteProtectRecord.sid:
logObj = "WriteProtect";
retval.writeProtect = (WriteProtectRecord) rec;
break;
case FileSharingRecord.sid:
logObj = "FileSharing";
retval.fileShare = (FileSharingRecord) rec;
break;
case NameCommentRecord.sid:
logObj = "NameComment";
final NameCommentRecord ncr = (NameCommentRecord) rec;
retval.commentRecords.put(ncr.getNameText(), ncr);
break;
case HyperlinkRecord.sid:
// Look for other interesting values that follow the EOFRecord
logObj = "Hyperlink";
retval.hyperlinks.add((HyperlinkRecord) rec);
break;
default:
logObj = "(sid=" + rec.getSid() + ")";
break;
}
if (!eofPassed) {
records.add(rec);
}
LOG.log(DEBUG, "found " + logObj + " record at " + k);
if (rec.getSid() == EOFRecord.sid) {
eofPassed = true;
}
}
if (retval.windowOne == null) {
retval.windowOne = createWindowOne();
}
LOG.log(DEBUG, "exit create workbook from existing file function");
return retval;
}
use of org.apache.poi.hssf.record.FormatRecord 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.FormatRecord in project poi by apache.
the class InternalWorkbook method createFormat.
/**
* Creates a FormatRecord, inserts it, and returns the index code.
* @param formatString the format string
* @return the index code of the format record.
* @see org.apache.poi.hssf.record.FormatRecord
* @see org.apache.poi.hssf.record.Record
*/
public int createFormat(String formatString) {
//Starting value from M$ empircal study.
maxformatid = maxformatid >= 0xa4 ? maxformatid + 1 : 0xa4;
FormatRecord rec = new FormatRecord(maxformatid, formatString);
int pos = 0;
while (pos < records.size() && records.get(pos).getSid() != FormatRecord.sid) {
pos++;
}
pos += formats.size();
formats.add(rec);
records.add(pos, rec);
return maxformatid;
}
use of org.apache.poi.hssf.record.FormatRecord in project poi by apache.
the class FormatTrackingHSSFListener method processRecordInternally.
/**
* Process the record ourselves, but do not pass it on to the child
* Listener.
*
* @param record the record to be processed
*/
public void processRecordInternally(Record record) {
if (record instanceof FormatRecord) {
FormatRecord fr = (FormatRecord) record;
_customFormatRecords.put(Integer.valueOf(fr.getIndexCode()), fr);
}
if (record instanceof ExtendedFormatRecord) {
ExtendedFormatRecord xr = (ExtendedFormatRecord) record;
_xfRecords.add(xr);
}
}
Aggregations