Example #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));
        }
Example #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;
            }
Example #3
0
            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));
            }
Example #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);

            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]);
            }
        }
Example #5
0
        /**
         * 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));
        }