Ejemplo n.º 1
0
        // 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));
        }
Ejemplo n.º 2
0
            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;
            }
Ejemplo n.º 3
0
            public ExternalBookBlock(RecordStream rs)
            {
                _externalBookRecord = (SupBookRecord)rs.GetNext();
                List <object> temp = new List <object>();

                while (rs.PeekNextClass() == typeof(ExternalNameRecord))
                {
                    temp.Add(rs.GetNext());
                }
                _externalNameRecords = (ExternalNameRecord[])temp.ToArray();

                temp.Clear();

                while (rs.PeekNextClass() == typeof(CRNCountRecord))
                {
                    temp.Add(new CRNBlock(rs));
                }
                _crnBlocks = (CRNBlock[])temp.ToArray();
            }
Ejemplo n.º 4
0
        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]);
            }
        }
Ejemplo n.º 5
0
        /**
         * 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();
        }
Ejemplo n.º 6
0
        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);
            }
        }