/** * Also collects any loose MergeCellRecords and puts them in the supplied * mergedCellsTable */ public RowBlocksReader(RecordStream rs) { List <object> plainRecords = new List <object>(); List <object> shFrmRecords = new List <object>(); List <object> arrayRecords = new List <object>(); List <object> tableRecords = new List <object>(); List <object> mergeCellRecords = new List <object>(); 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(); List <object> 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(); CellReference[] firstCells = new CellReference[firstCellRefs.Count]; firstCells = firstCellRefs.ToArray(); arrayRecs = new List <ArrayRecord>((ArrayRecord[])arrayRecords.ToArray()); tableRecs = new List <TableRecord>((TableRecord[])tableRecords.ToArray()); _plainRecords = plainRecords; _sfm = SharedValueManager.Create(sharedFormulaRecs, firstCells, arrayRecs, tableRecs); _mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.Count]; _mergedCellsRecords = (MergeCellsRecord[])mergeCellRecords.ToArray(); }
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); List <object> temp = new List <object>(); while (rs.PeekNextClass() == typeof(SupBookRecord)) { temp.Add(new ExternalBookBlock(rs)); } //_externalBookBlocks = new ExternalBookBlock[temp.Count]; _externalBookBlocks = (ExternalBookBlock[])temp.ToArray(); 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); commentRecords[ncr.NameText] = ncr; } else { break; } } _recordCount = rs.GetCountRead(); for (int i = startIndex; i < startIndex + _recordCount; i++) { _workbookRecordList.Records.Add(inputList[i]); } }
public InternalChart(RecordStream rs) { _plsRecords = new List <PLSAggregate>(); records = new List <RecordBase>(128); if (rs.PeekNextSid() != BOFRecord.sid) { throw new Exception("BOF record expected"); } BOFRecord bof = (BOFRecord)rs.GetNext(); if (bof.Type != BOFRecordType.Chart) { throw new RuntimeException("Bad BOF record type"); } records.Add(bof); while (rs.HasNext()) { int recSid = rs.PeekNextSid(); Record.Record rec = rs.GetNext(); if (recSid == EOFRecord.sid) { records.Add(rec); break; } if (recSid == ChartRecord.sid) { continue; } if (recSid == ChartFRTInfoRecord.sid) { _chartFrtInfo = (ChartFRTInfoRecord)rec; } else if (recSid == HeaderRecord.sid) { header = (HeaderRecord)rec; } else if (recSid == FooterRecord.sid) { footer = (FooterRecord)rec; } else if (recSid == HCenterRecord.sid) { _hCenter = (HCenterRecord)rec; } else if (recSid == VCenterRecord.sid) { _vCenter = (VCenterRecord)rec; } else if (recSid == LeftMarginRecord.sid) { _leftMargin = (LeftMarginRecord)rec; } else if (recSid == RightMarginRecord.sid) { _rightMargin = (RightMarginRecord)rec; } else if (recSid == TopMarginRecord.sid) { _topMargin = (TopMarginRecord)rec; } else if (recSid == BottomMarginRecord.sid) { _bottomMargin = (BottomMarginRecord)rec; } else if (recSid == UnknownRecord.PLS_004D) // PLS { PLSAggregate pls = new PLSAggregate(rs); PLSAggregateVisitor rv = new PLSAggregateVisitor(records); pls.VisitContainedRecords(rv); _plsRecords.Add(pls); continue; } else if (recSid == PrintSetupRecord.sid) { printSetup = (PrintSetupRecord)rec; } else if (recSid == PrintSizeRecord.sid) { _printSize = (PrintSizeRecord)rec; } else if (recSid == HeaderFooterRecord.sid) { HeaderFooterRecord hf = (HeaderFooterRecord)rec; if (hf.IsCurrentSheet) { _headerFooter = hf; } else { _sviewHeaderFooters.Add(hf); } } else if (recSid == ProtectRecord.sid) { _protect = (ProtectRecord)rec; } records.Add(rec); } }