示例#1
0
        /**
         * returns an appropriate Eval impl instance for the Ptg. The Ptg must be
         * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg,
         * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be
         * passed here!
         */
        private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec)
        {
            //  consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class)

            if (ptg is NamePtg)
            {
                // named ranges, macro functions
                NamePtg namePtg = (NamePtg)ptg;
                IEvaluationName nameRecord = _workbook.GetName(namePtg);
                if (nameRecord.IsFunctionName)
                {
                    return new NameEval(nameRecord.NameText);
                }
                if (nameRecord.HasFormula)
                {
                    return EvaluateNameFormula(nameRecord.NameDefinition, ec);
                }

                throw new Exception("Don't now how To evalate name '" + nameRecord.NameText + "'");
            }
            if (ptg is NameXPtg)
            {
                return ec.GetNameXEval(((NameXPtg)ptg));
            }

            if (ptg is IntPtg)
            {
                return new NumberEval(((IntPtg)ptg).Value);
            }
            if (ptg is NumberPtg)
            {
                return new NumberEval(((NumberPtg)ptg).Value);
            }
            if (ptg is StringPtg)
            {
                return new StringEval(((StringPtg)ptg).Value);
            }
            if (ptg is BoolPtg)
            {
                return BoolEval.ValueOf(((BoolPtg)ptg).Value);
            }
            if (ptg is ErrPtg)
            {
                return ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode);
            }
            if (ptg is MissingArgPtg)
            {
                return MissingArgEval.instance;
            }
            if (ptg is AreaErrPtg || ptg is RefErrorPtg
                    || ptg is DeletedArea3DPtg || ptg is DeletedRef3DPtg)
            {
                return ErrorEval.REF_INVALID;
            }
            if (ptg is Ref3DPtg)
            {
                Ref3DPtg rptg = (Ref3DPtg)ptg;
                return ec.GetRef3DEval(rptg.Row, rptg.Column, rptg.ExternSheetIndex);
            }
            if (ptg is Area3DPtg)
            {
                Area3DPtg aptg = (Area3DPtg)ptg;
                return ec.GetArea3DEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn, aptg.ExternSheetIndex);
            }
            if (ptg is RefPtg)
            {
                RefPtg rptg = (RefPtg)ptg;
                return ec.GetRefEval(rptg.Row, rptg.Column);
            }
            if (ptg is AreaPtg)
            {
                AreaPtg aptg = (AreaPtg)ptg;
                return ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn);
            }

            if (ptg is UnknownPtg)
            {
                // POI uses UnknownPtg when the encoded Ptg array seems To be corrupted.
                // This seems To occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790)
                // In any case, formulas are re-parsed before execution, so UnknownPtg should not Get here
                throw new RuntimeException("UnknownPtg not allowed");
            }
            if (ptg is ExpPtg)
            {
                // ExpPtg is used for array formulas and shared formulas.
                // it is currently unsupported, and may not even get implemented here
                throw new RuntimeException("ExpPtg currently not supported");
            }
            throw new RuntimeException("Unexpected ptg class (" + ptg.GetType().Name + ")");
        }
示例#2
0
 private static Double ConvertArrayNumber(Ptg ptg, bool isPositive)
 {
     double value;
     if (ptg is IntPtg)
     {
         value = ((IntPtg)ptg).Value;
     }
     else if (ptg is NumberPtg)
     {
         value = ((NumberPtg)ptg).Value;
     }
     else
     {
         throw new Exception("Unexpected ptg (" + ptg.GetType().Name + ")");
     }
     if (!isPositive)
     {
         value = -value;
     }
     return value;
 }
示例#3
0
 private static Ptg CreateDeletedRef(Ptg ptg)
 {
     if (ptg is RefPtg)
     {
         return new RefErrorPtg();
     }
     if (ptg is Ref3DPtg)
     {
         Ref3DPtg rptg = (Ref3DPtg)ptg;
         return new DeletedRef3DPtg(rptg.ExternSheetIndex);
     }
     if (ptg is AreaPtg)
     {
         return new AreaErrPtg();
     }
     if (ptg is Area3DPtg)
     {
         Area3DPtg area3DPtg = (Area3DPtg)ptg;
         return new DeletedArea3DPtg(area3DPtg.ExternSheetIndex);
     }
     if (ptg is Ref3DPxg)
     {
         Ref3DPxg pxg = (Ref3DPxg)ptg;
         return new Deleted3DPxg(pxg.ExternalWorkbookNumber, pxg.SheetName);
     }
     if (ptg is Area3DPxg)
     {
         Area3DPxg pxg = (Area3DPxg)ptg;
         return new Deleted3DPxg(pxg.ExternalWorkbookNumber, pxg.SheetName);
     }
     throw new ArgumentException("Unexpected ref ptg class (" + ptg.GetType().Name + ")");
 }