Пример #1
0
        /**
         * Converts all {@link FormulaRecord}s handled by <c>sharedFormulaRecord</c>
         * to plain unshared formulas
         */
        public void Unlink(SharedFormulaRecord sharedFormulaRecord)
        {
            SharedFormulaGroup svg = _groupsBySharedFormulaRecord[sharedFormulaRecord];

            _groupsBySharedFormulaRecord.Remove(sharedFormulaRecord);
            _groups = null; // be sure to reset cached value
            if (svg == null)
            {
                throw new InvalidOperationException("Failed to find formulas for shared formula");
            }
            svg.UnlinkSharedFormulas();
        }
Пример #2
0
        public void UnlinkSharedFormula()
        {
            SharedFormulaRecord sfr = _sharedFormulaRecord;

            if (sfr == null)
            {
                throw new InvalidOperationException("Formula not linked to shared formula");
            }
            Ptg[] ptgs = sfr.GetFormulaTokens(_formulaRecord);
            _formulaRecord.SetParsedExpression(ptgs);
            //Now its not shared!
            _formulaRecord.SetSharedFormula(false);
            _sharedFormulaRecord = null;
        }
Пример #3
0
            public SharedFormulaGroup(SharedFormulaRecord sfr, CellReference firstCell)
            {
                if (!sfr.IsInRange(firstCell.Row, firstCell.Col))
                {
                    throw new ArgumentException("First formula cell " + firstCell.FormatAsString()
                                                + " is not shared formula range " + sfr.Range.ToString() + ".");
                }
                _sfr       = sfr;
                _firstCell = firstCell;
                int width  = sfr.LastColumn - sfr.FirstColumn + 1;
                int height = sfr.LastRow - sfr.FirstRow + 1;

                _frAggs           = new FormulaRecordAggregate[width * height];
                _numberOfFormulas = 0;
            }
Пример #4
0
        public void TestConvertSharedFormulasOperandClasses_bug45123()
        {
            RecordInputStream in1        = TestcaseRecordInputStream.Create(0, SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
            short             encodedLen = in1.ReadShort();

            Ptg[] sharedFormula = Ptg.ReadTokens(encodedLen, in1);

            Ptg[] convertedFormula = SharedFormulaRecord.ConvertSharedFormulas(sharedFormula, 100, 200);

            RefPtg refPtg = (RefPtg)convertedFormula[1];

            Assert.AreEqual("$C101", refPtg.ToFormulaString());
            if (refPtg.PtgClass == Ptg.CLASS_REF)
            {
                throw new AssertFailedException("Identified bug 45123");
            }

            ConfirmOperandClasses(sharedFormula, convertedFormula);
        }
        private SharedValueManager(SharedFormulaRecord[] sharedFormulaRecords,
                                   CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords)
        {
            int nShF = sharedFormulaRecords.Length;

            if (nShF != firstCells.Length)
            {
                throw new ArgumentException("array sizes don't match: " + nShF + "!=" + firstCells.Length + ".");
            }
            _arrayRecords = arrayRecords;
            _tableRecords = tableRecords;
            Dictionary <SharedFormulaRecord, SharedFormulaGroup> m = new Dictionary <SharedFormulaRecord, SharedFormulaGroup>(nShF * 3 / 2);

            for (int i = 0; i < nShF; i++)
            {
                SharedFormulaRecord sfr = sharedFormulaRecords[i];
                m[sfr] = new SharedFormulaGroup(sfr, firstCells[i]);
            }
            _groupsBySharedFormulaRecord = m;
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormulaRecordAggregate"/> class.
        /// </summary>
        /// <param name="formulaRec">The formula rec.</param>
        /// <param name="stringRec">The string rec.</param>
        /// <param name="svm">The SVM.</param>
        public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm)
        {
            if (svm == null)
            {
                throw new ArgumentException("sfm must not be null");
            }
            if (formulaRec.HasCachedResultString)
            {
                if (stringRec == null)
                {
                    throw new RecordFormatException("Formula record flag is set but String record was not found");
                }
                _stringRecord = stringRec;
            }
            else
            {
                // Usually stringRec is null here (in agreement with what the formula rec says).
                // In the case where an extra StringRecord is erroneously present, Excel (2007)
                // ignores it (see bug 46213).
                _stringRecord = null;
            }

            _formulaRecord      = formulaRec;
            _sharedValueManager = svm;
            if (formulaRec.IsSharedFormula)
            {
                CellReference firstCell = formulaRec.Formula.ExpReference;
                if (firstCell == null)
                {
                    HandleMissingSharedFormulaRecord(formulaRec);
                }
                else
                {
                    _sharedFormulaRecord = svm.LinkSharedFormulaRecord(firstCell, this);
                }
            }
        }
Пример #7
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));
        }
Пример #8
0
        private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst)
        {
            Biff ret = record;

            switch (record.Id)
            {
            case (ushort)RecordType.Bof:
                BofRecord bof = new BofRecord(record);
                if (bof.Version < 0x0600)
                {
                    throw new Exception("Versions below Excel 97/2000 are currently not supported.");
                }

                ret = bof;
                break;

            case (ushort)RecordType.Boundsheet:
                ret = new BoundSheetRecord(record);
                break;

            case (ushort)RecordType.Index:
                ret = new IndexRecord(record);
                break;

            case (ushort)RecordType.DbCell:
                ret = new DbCellRecord(record);
                break;

            case (ushort)RecordType.Row:
                ret = new RowRecord(record);
                break;

            case (ushort)RecordType.Continue:
                ret = new ContinueRecord(record);
                break;

            case (ushort)RecordType.Blank:
                ret = new BlankRecord(record);
                break;

            case (ushort)RecordType.BoolErr:
                ret = new BoolErrRecord(record);
                break;

            case (ushort)RecordType.Formula:
                ret = new FormulaRecord(record, stream);
                break;

            case (ushort)RecordType.Label:
                ret = new LabelRecord(record);
                break;

            case (ushort)RecordType.LabelSst:
                ret = new LabelSstRecord(record, sst);
                break;

            case (ushort)RecordType.MulBlank:
                ret = new MulBlankRecord(record);
                break;

            case (ushort)RecordType.MulRk:
                ret = new MulRkRecord(record);
                break;

            case (ushort)RecordType.String:
                ret = new StringValueRecord(record);
                break;

            case (ushort)RecordType.Xf:
                ret = new XfRecord(record);
                break;

            case (ushort)RecordType.Rk:
                ret = new RkRecord(record);
                break;

            case (ushort)RecordType.Number:
                ret = new NumberRecord(record);
                break;

            case (ushort)RecordType.Array:
                ret = new ArrayRecord(record);
                break;

            case (ushort)RecordType.ShrFmla:
                ret = new SharedFormulaRecord(record);
                break;

            case (ushort)RecordType.Table:
                ret = new TableRecord(record);
                break;

            case (ushort)RecordType.Sst:
                ret = new SstRecord(record, stream);
                break;

            case (ushort)RecordType.Eof:
                ret = new EofRecord(record);
                break;

            case (ushort)RecordType.Font:
                ret = new FontRecord(record);
                break;

            case (ushort)RecordType.Format:
                ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record);
                break;

            case (ushort)RecordType.Palette:
                ret = new PaletteRecord(record);
                break;

            case (ushort)RecordType.Hyperlink:
                ret = new HyperLinkRecord(record);
                break;
            }

            return(ret);
        }