public CustomViewSettingsRecordAggregate(RecordStream rs) { _begin = rs.GetNext(); if (_begin.Sid != UserSViewBegin.sid) { throw new InvalidOperationException("Bad begin record"); } List<RecordBase> temp = new List<RecordBase>(); while (rs.PeekNextSid() != UserSViewEnd.sid) { if (PageSettingsBlock.IsComponentRecord(rs.PeekNextSid())) { if (_psBlock != null) { throw new InvalidOperationException( "Found more than one PageSettingsBlock in custom view Settings sub-stream"); } _psBlock = new PageSettingsBlock(rs); temp.Add(_psBlock); continue; } temp.Add(rs.GetNext()); } _recs = temp; _end = rs.GetNext(); // no need to save EOF in field if (_end.Sid != UserSViewEnd.sid) { throw new InvalidOperationException("Bad custom view Settings end record"); } }
public ChartSubstreamRecordAggregate(RecordStream rs) { _bofRec = (BOFRecord)rs.GetNext(); List<RecordBase> temp = new List<RecordBase>(); while (rs.PeekNextClass() != typeof(EOFRecord)) { Type a = rs.PeekNextClass(); if (PageSettingsBlock.IsComponentRecord(rs.PeekNextSid())) { if (_psBlock != null) { if (rs.PeekNextSid() == HeaderFooterRecord.sid) { // test samples: 45538_classic_Footer.xls, 45538_classic_Header.xls _psBlock.AddLateHeaderFooter((HeaderFooterRecord)rs.GetNext()); continue; } throw new InvalidDataException( "Found more than one PageSettingsBlock in chart sub-stream"); } _psBlock = new PageSettingsBlock(rs); temp.Add(_psBlock); continue; } temp.Add(rs.GetNext()); } _recs = temp; Record eof = rs.GetNext(); // no need to save EOF in field if (!(eof is EOFRecord)) { throw new InvalidOperationException("Bad chart EOF"); } }
private bool ReadARecord(RecordStream rs) { switch (rs.PeekNextSid()) { case ProtectRecord.sid: CheckNotPresent(_protectRecord); _protectRecord = rs.GetNext() as ProtectRecord; break; case ObjectProtectRecord.sid: CheckNotPresent(_objectProtectRecord); _objectProtectRecord = rs.GetNext() as ObjectProtectRecord; break; case ScenarioProtectRecord.sid: CheckNotPresent(_scenarioProtectRecord); _scenarioProtectRecord = rs.GetNext() as ScenarioProtectRecord; break; case PasswordRecord.sid: CheckNotPresent(_passwordRecord); _passwordRecord = rs.GetNext() as PasswordRecord; break; default: // all other record types are not part of the PageSettingsBlock return false; } return true; }
public DataValidityTable(RecordStream rs) { _headerRec = (DVALRecord)rs.GetNext(); IList temp = new ArrayList(); while (rs.PeekNextClass() == typeof(DVRecord)) { temp.Add(rs.GetNext()); } _validationList = temp; }
// TODO make this class into a record aggregate private static ExternSheetRecord ReadExtSheetRecord(RecordStream rs) { List<ExternSheetRecord> temp = new List<ExternSheetRecord>(2); while (rs.PeekNextClass() == typeof(ExternSheetRecord)) { temp.Add((ExternSheetRecord)rs.GetNext()); } int nItems = temp.Count; if (nItems < 1) { throw new Exception("Expected an EXTERNSHEET record but got (" + rs.PeekNextClass().Name + ")"); } if (nItems == 1) { // this is the normal case. There should be just one ExternSheetRecord return temp[0]; } // Some apps generate multiple ExternSheetRecords (see bug 45698). // It seems like the best thing to do might be to combine these into one ExternSheetRecord[] esrs = new ExternSheetRecord[nItems]; esrs = temp.ToArray(); return ExternSheetRecord.Combine(esrs); }
public PLSAggregate(RecordStream rs) { _pls = rs.GetNext(); if (rs.PeekNextSid() == ContinueRecord.sid) { List<ContinueRecord> temp = new List<ContinueRecord>(); while (rs.PeekNextSid() == ContinueRecord.sid) { temp.Add((ContinueRecord)rs.GetNext()); } _plsContinues = new ContinueRecord[temp.Count]; _plsContinues = temp.ToArray(); } else { _plsContinues = EMPTY_CONTINUE_RECORD_ARRAY; } }
/** * Reads zero or more consecutive {@link MergeCellsRecord}s * @param rs */ public void Read(RecordStream rs) { while (rs.PeekNextClass() == typeof(MergeCellsRecord)) { MergeCellsRecord mcr = (MergeCellsRecord)rs.GetNext(); int nRegions = mcr.NumAreas; for (int i = 0; i < nRegions; i++) { _mergedRegions.Add(mcr.GetAreaAt(i)); } } }
/// <summary> /// Initializes a new instance of the <see cref="ColumnInfoRecordsAggregate"/> class. /// </summary> /// <param name="rs">The rs.</param> public ColumnInfoRecordsAggregate(RecordStream rs): this() { bool isInOrder = true; ColumnInfoRecord cirPrev = null; while (rs.PeekNextClass() == typeof(ColumnInfoRecord)) { ColumnInfoRecord cir = (ColumnInfoRecord)rs.GetNext(); records.Add(cir); if (cirPrev != null && CIRComparator.CompareColInfos(cirPrev, cir) > 0) { isInOrder = false; } cirPrev = cir; } if (records.Count < 1) { throw new InvalidOperationException("No column info records found"); } if (!isInOrder) { records.Sort(CIRComparator.instance); } }
public void Construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) { if (rec is FormulaRecord) { FormulaRecord formulaRec = (FormulaRecord)rec; // read optional cached text value StringRecord cachedText=null; Type nextClass = rs.PeekNextClass(); if (nextClass == typeof(StringRecord)) { cachedText = (StringRecord)rs.GetNext(); } else { cachedText = null; } InsertCell(new FormulaRecordAggregate(formulaRec, cachedText, sfh)); } else { InsertCell(rec); } }
/// <summary> /// Create CFRecordsAggregate from a list of CF Records /// </summary> /// <param name="rs">list of Record objects</param> public static CFRecordsAggregate CreateCFAggregate(RecordStream rs) { Record rec = rs.GetNext(); if (rec.Sid != CFHeaderRecord.sid) { throw new InvalidOperationException("next record sid was " + rec.Sid + " instead of " + CFHeaderRecord.sid + " as expected"); } CFHeaderRecord header = (CFHeaderRecord)rec; int nRules = header.NumberOfConditionalFormats; CFRuleRecord[] rules = new CFRuleRecord[nRules]; for (int i = 0; i < rules.Length; i++) { rules[i] = (CFRuleRecord)rs.GetNext(); } return new CFRecordsAggregate(header, rules); }
/** * Also collects any loose MergeCellRecords and puts them in the supplied * mergedCellsTable */ public RowBlocksReader(RecordStream rs) { ArrayList plainRecords = new ArrayList(); ArrayList shFrmRecords = new ArrayList(); ArrayList arrayRecords = new ArrayList(); ArrayList tableRecords = new ArrayList(); ArrayList mergeCellRecords = new ArrayList(); List<CellReference> firstCellRefs = new List<CellReference>(); Record prevRec = null; while (!RecordOrderer.IsEndOfRowBlock(rs.PeekNextSid())) { // End of row/cell records for the current sheet // Note - It is important that this code does not inadvertently add any sheet // records from a subsequent sheet. For example, if SharedFormulaRecords // are taken from the wrong sheet, this could cause bug 44449. if (!rs.HasNext()) { throw new InvalidOperationException("Failed to find end of row/cell records"); } Record rec = rs.GetNext(); ArrayList dest; switch (rec.Sid) { case MergeCellsRecord.sid: dest = mergeCellRecords; break; case SharedFormulaRecord.sid: dest = shFrmRecords; if (!(prevRec is FormulaRecord)) { throw new Exception("Shared formula record should follow a FormulaRecord"); } FormulaRecord fr = (FormulaRecord)prevRec; firstCellRefs.Add(new CellReference(fr.Row, fr.Column)); break; case ArrayRecord.sid: dest = arrayRecords; break; case TableRecord.sid: dest = tableRecords; break; default: dest = plainRecords; break; } dest.Add(rec); prevRec = rec; } SharedFormulaRecord[] sharedFormulaRecs = new SharedFormulaRecord[shFrmRecords.Count]; List<ArrayRecord> arrayRecs = new List<ArrayRecord>(arrayRecords.Count); List<TableRecord> tableRecs = new List<TableRecord>(tableRecords.Count); sharedFormulaRecs = (SharedFormulaRecord[])shFrmRecords.ToArray(typeof(SharedFormulaRecord)); CellReference[] firstCells = new CellReference[firstCellRefs.Count]; firstCells=firstCellRefs.ToArray(); arrayRecs = new List<ArrayRecord>((ArrayRecord[])arrayRecords.ToArray(typeof(ArrayRecord))); tableRecs = new List<TableRecord>((TableRecord[])tableRecords.ToArray(typeof(TableRecord))); _plainRecords = plainRecords; _sfm = SharedValueManager.Create(sharedFormulaRecs,firstCells, arrayRecs, tableRecs); _mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.Count]; _mergedCellsRecords = (MergeCellsRecord[])mergeCellRecords.ToArray(typeof(MergeCellsRecord)); }
/// <summary> /// Initializes a new instance of the <see cref="InternalSheet"/> class. /// </summary> /// <param name="rs">The stream.</param> private InternalSheet(RecordStream rs) { _mergedCellsTable = new MergedCellsTable(); RowRecordsAggregate rra = null; records = new List<RecordBase>(128); // TODO - take chart streams off into separate java objects //int bofEofNestingLevel = 0; // nesting level can only get to 2 (when charts are present) int dimsloc = -1; if (rs.PeekNextSid() != BOFRecord.sid) { throw new Exception("BOF record expected"); } BOFRecord bof = (BOFRecord)rs.GetNext(); if (bof.Type != BOFRecord.TYPE_WORKSHEET) { // TODO - fix junit tests throw new RuntimeException("Bad BOF record type"); } records.Add(bof); while (rs.HasNext()) { int recSid = rs.PeekNextSid(); if (recSid == CFHeaderRecord.sid) { condFormatting = new ConditionalFormattingTable(rs); records.Add(condFormatting); continue; } if (recSid == ColumnInfoRecord.sid) { _columnInfos = new ColumnInfoRecordsAggregate(rs); records.Add(_columnInfos); continue; } if (recSid == DVALRecord.sid) { _dataValidityTable = new DataValidityTable(rs); records.Add(_dataValidityTable); continue; } if (RecordOrderer.IsRowBlockRecord(recSid)) { //only Add the aggregate once if (rra != null) { throw new InvalidOperationException("row/cell records found in the wrong place"); } RowBlocksReader rbr = new RowBlocksReader(rs); _mergedCellsTable.AddRecords(rbr.LooseMergedCells); rra = new RowRecordsAggregate(rbr.PlainRecordStream, rbr.SharedFormulaManager); records.Add(rra); //only Add the aggregate once continue; } if (CustomViewSettingsRecordAggregate.IsBeginRecord(recSid)) { // This happens three times in test sample file "29982.xls" // Also several times in bugzilla samples 46840-23373 and 46840-23374 records.Add(new CustomViewSettingsRecordAggregate(rs)); continue; } if (PageSettingsBlock.IsComponentRecord(recSid)) { if (_psBlock == null) { // first PSB record encountered - read all of them: _psBlock = new PageSettingsBlock(rs); records.Add(_psBlock); } else { // one or more PSB records found after some intervening non-PSB records _psBlock.AddLateRecords(rs); } // YK: in some cases records can be moved to the preceding // CustomViewSettingsRecordAggregate blocks _psBlock.PositionRecords(records); continue; } if (WorksheetProtectionBlock.IsComponentRecord(recSid)) { _protectionBlock.AddRecords(rs); continue; } if (recSid == MergeCellsRecord.sid) { // when the MergedCellsTable is found in the right place, we expect those records to be contiguous _mergedCellsTable.Read(rs); continue; } if (recSid == BOFRecord.sid) { ChartSubstreamRecordAggregate chartAgg = new ChartSubstreamRecordAggregate(rs); //if (false) //{ // TODO - would like to keep the chart aggregate packed, but one unit test needs attention // records.Add(chartAgg); //} //else //{ SpillAggregate(chartAgg, records); //} continue; } Record rec = rs.GetNext(); if (recSid == IndexRecord.sid) { // ignore INDEX record because it is only needed by Excel, // and POI always re-calculates its contents continue; } if (recSid == UncalcedRecord.sid) { // don't Add UncalcedRecord to the list _isUncalced = true; // this flag is enough continue; } if (recSid == FeatRecord.sid || recSid == FeatHdrRecord.sid) { records.Add(rec); continue; } if (recSid == EOFRecord.sid) { records.Add(rec); break; } if (recSid == DimensionsRecord.sid) { // Make a columns aggregate if one hasn't Ready been created. if (_columnInfos == null) { _columnInfos = new ColumnInfoRecordsAggregate(); records.Add(_columnInfos); } _dimensions = (DimensionsRecord)rec; dimsloc = records.Count; } else if (recSid == DefaultColWidthRecord.sid) { defaultcolwidth = (DefaultColWidthRecord)rec; } else if (recSid == DefaultRowHeightRecord.sid) { defaultrowheight = (DefaultRowHeightRecord)rec; } else if (recSid == PrintGridlinesRecord.sid) { printGridlines = (PrintGridlinesRecord)rec; } else if (recSid == GridsetRecord.sid) { gridset = (GridsetRecord)rec; } else if (recSid == SelectionRecord.sid) { selection = (SelectionRecord)rec; } else if (recSid == WindowTwoRecord.sid) { windowTwo = (WindowTwoRecord)rec; } else if (recSid == SheetExtRecord.sid) { sheetext = (SheetExtRecord)rec; } else if (recSid == GutsRecord.sid) { _gutsRecord = (GutsRecord)rec; } records.Add(rec); } if (windowTwo == null) { throw new InvalidOperationException("WINDOW2 was not found"); } if (_dimensions == null) { // Excel seems to always write the DIMENSION record, but tolerates when it is not present // in all cases Excel (2007) adds the missing DIMENSION record if (rra == null) { // bug 46206 alludes to files which skip the DIMENSION record // when there are no row/cell records. // Not clear which application wrote these files. rra = new RowRecordsAggregate(); } else { //log.log(POILogger.WARN, "DIMENSION record not found even though row/cells present"); // Not sure if any tools write files like this, but Excel reads them OK } dimsloc = FindFirstRecordLocBySid(WindowTwoRecord.sid); _dimensions = rra.CreateDimensions(); records.Insert(dimsloc, _dimensions); } if (rra == null) { rra = new RowRecordsAggregate(); records.Insert(dimsloc + 1, rra); } _rowsAggregate = rra; // put merged cells table in the right place (regardless of where the first MergedCellsRecord was found */ RecordOrderer.AddNewSheetRecord(records, _mergedCellsTable); RecordOrderer.AddNewSheetRecord(records, _protectionBlock); //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "sheet createSheet (existing file) exited"); }
public CRNBlock(RecordStream rs) { _countRecord = (CRNCountRecord)rs.GetNext(); int nCRNs = _countRecord.NumberOfCRNs; CRNRecord[] crns = new CRNRecord[nCRNs]; for (int i = 0; i < crns.Length; i++) { crns[i] = (CRNRecord)rs.GetNext(); } _crns = crns; }
private WorkbookRecordList _workbookRecordList; // TODO - would be nice to Remove this public LinkTable(List<Record> inputList, int startIndex, WorkbookRecordList workbookRecordList, Dictionary<String, NameCommentRecord> commentRecords) { _workbookRecordList = workbookRecordList; RecordStream rs = new RecordStream(inputList, startIndex); ArrayList temp = new ArrayList(); while (rs.PeekNextClass() == typeof(SupBookRecord)) { temp.Add(new ExternalBookBlock(rs)); } //_externalBookBlocks = new ExternalBookBlock[temp.Count]; _externalBookBlocks = (ExternalBookBlock[])temp.ToArray(typeof(ExternalBookBlock)); temp.Clear(); if (_externalBookBlocks.Length > 0) { // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord if (rs.PeekNextClass() != typeof(ExternSheetRecord)) { // not quite - if written by google docs _externSheetRecord = null; } else { _externSheetRecord = ReadExtSheetRecord(rs); } } else { _externSheetRecord = null; } _definedNames = new List<NameRecord>(); // collect zero or more DEFINEDNAMEs id=0x18 while (true) { Type nextClass = rs.PeekNextClass(); if (nextClass == typeof(NameRecord)) { NameRecord nr = (NameRecord)rs.GetNext(); _definedNames.Add(nr); } else if (nextClass == typeof(NameCommentRecord)) { NameCommentRecord ncr = (NameCommentRecord)rs.GetNext(); commentRecords.Add(ncr.NameText, ncr); } else { break; } } _recordCount = rs.GetCountRead(); for (int i = startIndex; i < startIndex + _recordCount; i++) { _workbookRecordList.Records.Add(inputList[i]); } }
public ExternalBookBlock(RecordStream rs) { _externalBookRecord = (SupBookRecord)rs.GetNext(); ArrayList temp = new ArrayList(); while (rs.PeekNextClass() == typeof(ExternalNameRecord)) { temp.Add(rs.GetNext()); } _externalNameRecords = (ExternalNameRecord[])temp.ToArray(typeof(ExternalNameRecord)); temp.Clear(); while (rs.PeekNextClass() == typeof(CRNCountRecord)) { temp.Add(new CRNBlock(rs)); } _crnBlocks = (CRNBlock[])temp.ToArray(typeof(CRNBlock)); }
/** * @param rs record stream with all {@link SharedFormulaRecord} * {@link ArrayRecord}, {@link TableRecord} {@link MergeCellsRecord} Records removed */ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) : this(svm) { while (rs.HasNext()) { Record rec = rs.GetNext(); switch (rec.Sid) { case RowRecord.sid: InsertRow((RowRecord)rec); continue; case DBCellRecord.sid: // end of 'Row Block'. Should only occur after cell records // ignore DBCELL records because POI generates them upon re-serialization continue; } if (rec is UnknownRecord) { // might need to keep track of where exactly these belong AddUnknownRecord((UnknownRecord)rec); while (rs.PeekNextSid() == ContinueRecord.sid) { AddUnknownRecord(rs.GetNext()); } continue; } if (rec is MulBlankRecord) { _valuesAgg.AddMultipleBlanks((MulBlankRecord) rec); continue; } if (!(rec is CellValueRecordInterface)) { throw new InvalidOperationException("Unexpected record type (" + rec.GetType().Name + ")"); } _valuesAgg.Construct((CellValueRecordInterface)rec, rs, svm); } }