Пример #1
0
        protected override void AppendValueText(StringBuilder buffer)
        {
            buffer.Append("    .value           = ");
            if (specialCachedValue == null)
            {
                buffer.Append(field_4_value).Append("\n");
            }
            else
            {
                buffer.Append(specialCachedValue.FormatDebugString).Append("\n");
            }
            buffer.Append("    .options         = ").Append(Options).Append("\n");
            buffer.Append("      .alwaysCalc         = ").Append(alwaysCalc.IsSet(Options)).Append("\n");
            buffer.Append("      .CalcOnLoad         = ").Append(calcOnLoad.IsSet(Options)).Append("\n");
            buffer.Append("      .sharedFormula         = ").Append(sharedFormula.IsSet(Options)).Append("\n");
            buffer.Append("    .zero            = ").Append(field_6_zero).Append("\n");

            Ptg[] ptgs = field_8_parsed_expr.Tokens;
            for (int k = 0; k < ptgs.Length; k++)
            {
                buffer.Append("	 Ptg[").Append(k).Append("]=");
                Ptg ptg = ptgs[k];
                buffer.Append(ptg.ToString()).Append(ptg.RVAType).Append("\n");
            }
        }
Пример #2
0
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("[AI]\n");
            buffer.Append("    .linkType             = ")
            .Append(HexDump.ByteToHex(LinkType)).Append('\n');
            buffer.Append(Environment.NewLine);
            buffer.Append("    .referenceType        = ").Append(HexDump.ByteToHex(ReferenceType)).Append('\n');
            buffer.Append(Environment.NewLine);
            buffer.Append("    .options              = ").Append(HexDump.ShortToHex(Options)).Append('\n');
            buffer.Append(Environment.NewLine);
            buffer.Append("         .customNumberFormat       = ").Append(IsCustomNumberFormat).Append('\n');
            buffer.Append("    .indexNumberFmtRecord = ")
            .Append(HexDump.ShortToHex(IndexNumberFmtRecord)).Append('\n');
            buffer.Append(Environment.NewLine);
            buffer.Append("    .formulaOfLink        = ");
            Ptg[] ptgs = field_5_formulaOfLink.Tokens;
            for (int i = 0; i < ptgs.Length; i++)
            {
                Ptg ptg = ptgs[i];
                buffer.Append(ptg.ToString()).Append(ptg.RVAType).Append('\n');
            }

            buffer.Append("[/AI]\n");
            return(buffer.ToString());
        }
Пример #3
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[ftPictFmla]\n");
            sb.Append("    .f2unknown     = ").Append(HexDump.IntToHex(field_1_unknown_int)).Append("\n");
            if (field_2_refPtg == null)
            {
                sb.Append("    .f3unknown     = ").Append(HexDump.ToHex(field_2_unknownFormulaData)).Append("\n");
            }
            else
            {
                sb.Append("    .formula       = ").Append(field_2_refPtg.ToString()).Append("\n");
            }
            if (field_4_ole_classname != null)
            {
                sb.Append("    .unicodeFlag   = ").Append(field_3_unicode_flag).Append("\n");
                sb.Append("    .oleClassname  = ").Append(field_4_ole_classname).Append("\n");
            }
            if (field_4_unknownByte != null)
            {
                sb.Append("    .f4unknown   = ").Append(HexDump.ByteToHex(Convert.ToByte(field_4_unknownByte))).Append("\n");
            }
            if (field_5_stream_id != null)
            {
                sb.Append("    .streamId      = ").Append(HexDump.IntToHex(Convert.ToInt32(field_5_stream_id))).Append("\n");
            }
            if (field_6_unknown.Length > 0)
            {
                sb.Append("    .f7unknown     = ").Append(HexDump.ToHex(field_6_unknown)).Append("\n");
            }
            sb.Append("[/ftPictFmla]");
            return(sb.ToString());
        }
Пример #4
0
        private void ConfirmTokenClass(Ptg[] ptgs, int i, byte operandClass)
        {
            Ptg ptg = ptgs[i];

            if (ptg.IsBaseToken)
            {
                throw new AssertionException("ptg[" + i + "] is a base token");
            }
            if (operandClass != ptg.PtgClass)
            {
                throw new AssertionException("Wrong operand class for ptg ("
                                             + ptg.ToString() + "). Expected " + GetOperandClassName(operandClass)
                                             + " but got " + GetOperandClassName(ptg.PtgClass));
            }
        }
Пример #5
0
        /*
         * 20 00
         * 00
         * 01
         * 1A 00 // sz = 0x1A = 26
         * 00 00
         * 01 00
         * 00
         * 00
         * 00
         * 00
         * 00 // Unicode flag
         * 07 // name
         *
         * 29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26
         * 00 07 00 07 00 00 00 FF 00 10                   //  }
         *
         *
         *
         * 20 00
         * 00
         * 01
         * 0B 00 // sz = 0xB = 11
         * 00 00
         * 01 00
         * 00
         * 00
         * 00
         * 00
         * 00 // Unicode flag
         * 07 // name
         *
         * 3B 00 00 07 00 07 00 00 00 FF 00   // { 11 }
         */
        /*
         * 18, 00,
         * 1B, 00,
         *
         * 20, 00,
         * 00,
         * 01,
         * 0B, 00,
         * 00,
         * 00,
         * 00,
         * 00,
         * 00,
         * 07,
         * 3B 00 00 07 00 07 00 00 00 FF 00 ]
         */

        /**
         * @see Object#ToString()
         */
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("[NAME]\n");
            buffer.Append("    .option flags         = ").Append(HexDump.ToHex(field_1_option_flag))
            .Append("\n");
            buffer.Append("    .keyboard shortcut    = ").Append(HexDump.ToHex(field_2_keyboard_shortcut))
            .Append("\n");
            buffer.Append("    .Length of the name   = ").Append(NameTextLength)
            .Append("\n");
            buffer.Append("    .extSheetIx(1-based, 0=Global)= ").Append(field_5_externSheetIndex_plus1)
            .Append("\n");
            buffer.Append("    .sheetTabIx           = ").Append(field_6_sheetNumber)
            .Append("\n");
            buffer.Append("    .Length of menu text (Char count)        = ").Append(field_14_custom_menu_text.Length)
            .Append("\n");
            buffer.Append("    .Length of description text (Char count) = ").Append(field_15_description_text.Length)
            .Append("\n");
            buffer.Append("    .Length of help topic text (Char count)  = ").Append(field_16_help_topic_text.Length)
            .Append("\n");
            buffer.Append("    .Length of status bar text (Char count)  = ").Append(field_17_status_bar_text.Length)
            .Append("\n");
            buffer.Append("    .Name (Unicode flag)  = ").Append(field_11_nameIsMultibyte)
            .Append("\n");
            buffer.Append("    .Name (Unicode text)  = ").Append(NameText)
            .Append("\n");
            Ptg[] ptgs = field_13_name_definition.Tokens;
            buffer.AppendLine("    .Formula (nTokens=" + ptgs.Length + "):");
            for (int i = 0; i < ptgs.Length; i++)
            {
                Ptg ptg = ptgs[i];
                buffer.Append("       " + ptg.ToString()).Append(ptg.RVAType).Append("\n");
            }

            buffer.Append("    .Menu text (Unicode string without Length field)        = ").Append(field_14_custom_menu_text)
            .Append("\n");
            buffer.Append("    .Description text (Unicode string without Length field) = ").Append(field_15_description_text)
            .Append("\n");
            buffer.Append("    .Help topic text (Unicode string without Length field)  = ").Append(field_16_help_topic_text)
            .Append("\n");
            buffer.Append("    .Status bar text (Unicode string without Length field)  = ").Append(field_17_status_bar_text)
            .Append("\n");
            buffer.Append("[/NAME]\n");

            return(buffer.ToString());
        }
Пример #6
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(GetType().Name).Append(" [ARRAY]\n");
            sb.Append(" range=").Append(Range.ToString()).Append("\n");
            sb.Append(" options=").Append(HexDump.ShortToHex(_options)).Append("\n");
            sb.Append(" notUsed=").Append(HexDump.IntToHex(_field3notUsed)).Append("\n");
            sb.Append(" formula:").Append("\n");
            Ptg[] ptgs = _formula.Tokens;
            for (int i = 0; i < ptgs.Length; i++)
            {
                Ptg ptg = ptgs[i];
                sb.Append(ptg.ToString()).Append(ptg.RVAType).Append("\n");
            }
            sb.Append("]");
            return(sb.ToString());
        }
Пример #7
0
 public override String ToString()
 {
     StringBuilder sb = new StringBuilder();
     sb.Append("[EXTERNALNAME]\n");
     sb.Append("    .options      = ").Append(field_1_option_flag).Append("\n");
     sb.Append("    .ix      = ").Append(field_2_ixals).Append("\n");
     sb.Append("    .name    = ").Append(field_4_name).Append("\n");
     if (field_5_name_definition != null)
     {
         Ptg[] ptgs = field_5_name_definition.Tokens;
         for (int i = 0; i < ptgs.Length; i++)
         {
             Ptg ptg = ptgs[i];
             sb.Append(ptg.ToString()).Append(ptg.RVAType).Append("\n");
         }
     }
     sb.Append("[/EXTERNALNAME]\n");
     return sb.ToString();
 }
Пример #8
0
        /**
         * print a sort of string representation ([SHARED FORMULA RECORD] id = x [/SHARED FORMULA RECORD])
         */

        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("[SHARED FORMULA (").Append(HexDump.IntToHex(sid)).Append("]\n");
            buffer.Append("    .range      = ").Append(Range.ToString()).Append("\n");
            buffer.Append("    .reserved    = ").Append(HexDump.ShortToHex(field_5_reserved)).Append("\n");

            Ptg[] ptgs = field_7_parsed_expr.Tokens;
            for (int k = 0; k < ptgs.Length; k++)
            {
                buffer.Append("Formula[").Append(k).Append("]");
                Ptg ptg = ptgs[k];
                buffer.Append(ptg.ToString()).Append(ptg.RVAType).Append("\n");
            }

            buffer.Append("[/SHARED FORMULA]\n");
            return(buffer.ToString());
        }
Пример #9
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder(256);

            sb.Append("[ftLbsData]\n");
            sb.Append("    .unknownshort1 =").Append(HexDump.ShortToHex(_cbFContinued)).Append("\n");
            sb.Append("    .formula        = ").Append('\n');
            sb.Append(_linkPtg.ToString()).Append(_linkPtg.RVAType).Append('\n');
            sb.Append("    .nEntryCount   =").Append(HexDump.ShortToHex(_cLines)).Append("\n");
            sb.Append("    .selEntryIx    =").Append(HexDump.ShortToHex(_iSel)).Append("\n");
            sb.Append("    .style         =").Append(HexDump.ShortToHex(_flags)).Append("\n");
            sb.Append("    .unknownshort10=").Append(HexDump.ShortToHex(_idEdit)).Append("\n");
            if (_dropData != null)
            {
                sb.Append('\n').Append(_dropData.ToString());
            }
            sb.Append("[/ftLbsData]\n");
            return(sb.ToString());
        }
Пример #10
0
        private void ConfirmCell(ICell formulaCell, String formula, HSSFWorkbook wb)
        {
            Ptg[] excelPtgs    = FormulaExtractor.GetPtgs(formulaCell);
            Ptg[] poiPtgs      = HSSFFormulaParser.Parse(formula, wb);
            int   nExcelTokens = excelPtgs.Length;
            int   nPoiTokens   = poiPtgs.Length;

            if (nExcelTokens != nPoiTokens)
            {
                if (nExcelTokens == nPoiTokens + 1 && excelPtgs[0].GetType() == typeof(AttrPtg))
                {
                    // compensate for missing tAttrVolatile, which belongs in any formula
                    // involving OFFSET() et al. POI currently does not insert where required
                    Ptg[] temp = new Ptg[nExcelTokens];
                    temp[0] = excelPtgs[0];
                    Array.Copy(poiPtgs, 0, temp, 1, nPoiTokens);
                    poiPtgs = temp;
                }
                else
                {
                    throw new Exception("Expected " + nExcelTokens + " tokens but got "
                                        + nPoiTokens);
                }
            }
            bool          hasMismatch = false;
            StringBuilder sb          = new StringBuilder();

            for (int i = 0; i < nExcelTokens; i++)
            {
                Ptg poiPtg   = poiPtgs[i];
                Ptg excelPtg = excelPtgs[i];
                if (excelPtg.GetType() != poiPtg.GetType())
                {
                    hasMismatch = true;
                    sb.Append("  mismatch token type[" + i + "] " + GetShortClassName(excelPtg) + " "
                              + excelPtg.RVAType + " - " + GetShortClassName(poiPtg) + " "
                              + poiPtg.RVAType);
                    sb.Append(Environment.NewLine);
                    continue;
                }
                if (poiPtg.IsBaseToken)
                {
                    continue;
                }
                sb.Append("  token[" + i + "] " + excelPtg.ToString() + " "
                          + excelPtg.RVAType);

                if (excelPtg.PtgClass != poiPtg.PtgClass)
                {
                    hasMismatch = true;
                    sb.Append(" - was " + poiPtg.RVAType);
                }
                sb.Append(Environment.NewLine);
            }
            //if (false)
            //{ // Set 'true' to see trace of RVA values
            //    Console.WriteLine(formula);
            //    Console.WriteLine(sb.ToString());
            //}
            if (hasMismatch)
            {
                throw new AssertionException(sb.ToString());
            }
        }
Пример #11
0
        // visibility raised for testing
        /* package */

        public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs)
        {
            string dbgIndentStr = "";           // always init. to non-null just for defensive avoiding NPE

            if (dbgEvaluationOutputForNextEval)
            {
                // first evaluation call when ouput is desired, so iit. this evaluator instance
                dbgEvaluationOutputIndent      = 1;
                dbgEvaluationOutputForNextEval = false;
            }
            if (dbgEvaluationOutputIndent > 0)
            {
                // init. indent string to needed spaces (create as substring vom very long space-only string;
                // limit indendation for deep recursions)
                dbgIndentStr = "                                                                                                    ";
                dbgIndentStr = dbgIndentStr.Substring(0, Math.Min(dbgIndentStr.Length, dbgEvaluationOutputIndent * 2));
                EVAL_LOG.Log(POILogger.WARN, dbgIndentStr
                             + "- evaluateFormula('" + ec.GetRefEvaluatorForCurrentSheet().SheetNameRange
                             + "'/" + new CellReference(ec.RowIndex, ec.ColumnIndex).FormatAsString()
                             + "): " + Arrays.ToString(ptgs).Replace("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""));
                dbgEvaluationOutputIndent++;
            }

            Stack <ValueEval> stack = new Stack <ValueEval>();

            for (int i = 0, iSize = ptgs.Length; i < iSize; i++)
            {
                // since we don't know how To handle these yet :(
                Ptg ptg = ptgs[i];
                if (dbgEvaluationOutputIndent > 0)
                {
                    EVAL_LOG.Log(POILogger.INFO, dbgIndentStr + "  * ptg " + i + ": " + ptg.ToString());
                }
                if (ptg is AttrPtg)
                {
                    AttrPtg attrPtg = (AttrPtg)ptg;
                    if (attrPtg.IsSum)
                    {
                        // Excel prefers To encode 'SUM()' as a tAttr Token, but this evaluator
                        // expects the equivalent function Token
                        //byte nArgs = 1;  // tAttrSum always Has 1 parameter
                        ptg = FuncVarPtg.SUM;//.Create("SUM", nArgs);
                    }
                    if (attrPtg.IsOptimizedChoose)
                    {
                        ValueEval arg0      = stack.Pop();
                        int[]     jumpTable = attrPtg.JumpTable;
                        int       dist;
                        int       nChoices = jumpTable.Length;
                        try
                        {
                            int switchIndex = Choose.EvaluateFirstArg(arg0, ec.RowIndex, ec.ColumnIndex);
                            if (switchIndex < 1 || switchIndex > nChoices)
                            {
                                stack.Push(ErrorEval.VALUE_INVALID);
                                dist = attrPtg.ChooseFuncOffset + 4; // +4 for tFuncFar(CHOOSE)
                            }
                            else
                            {
                                dist = jumpTable[switchIndex - 1];
                            }
                        }
                        catch (EvaluationException e)
                        {
                            stack.Push(e.GetErrorEval());
                            dist = attrPtg.ChooseFuncOffset + 4; // +4 for tFuncFar(CHOOSE)
                        }
                        // Encoded dist for tAttrChoose includes size of jump table, but
                        // countTokensToBeSkipped() does not (it counts whole tokens).
                        dist -= nChoices * 2 + 2; // subtract jump table size
                        i    += CountTokensToBeSkipped(ptgs, i, dist);
                        continue;
                    }
                    if (attrPtg.IsOptimizedIf)
                    {
                        ValueEval arg0 = stack.Pop();
                        bool      evaluatedPredicate;
                        try
                        {
                            evaluatedPredicate = If.EvaluateFirstArg(arg0, ec.RowIndex, ec.ColumnIndex);
                        }
                        catch (EvaluationException e)
                        {
                            stack.Push(e.GetErrorEval());
                            int dist = attrPtg.Data;
                            i      += CountTokensToBeSkipped(ptgs, i, dist);
                            attrPtg = (AttrPtg)ptgs[i];
                            dist    = attrPtg.Data + 1;
                            i      += CountTokensToBeSkipped(ptgs, i, dist);
                            continue;
                        }
                        if (evaluatedPredicate)
                        {
                            // nothing to skip - true param folows
                        }
                        else
                        {
                            int dist = attrPtg.Data;
                            i += CountTokensToBeSkipped(ptgs, i, dist);
                            Ptg nextPtg = ptgs[i + 1];
                            if (ptgs[i] is AttrPtg && nextPtg is FuncVarPtg &&
                                // in order to verify that there is no third param, we need to check
                                // if we really have the IF next or some other FuncVarPtg as third param, e.g. ROW()/COLUMN()!
                                ((FuncVarPtg)nextPtg).FunctionIndex == FunctionMetadataRegistry.FUNCTION_INDEX_IF)
                            {
                                // this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
                                i++;
                                stack.Push(BoolEval.FALSE);
                            }
                        }
                        continue;
                    }
                    if (attrPtg.IsSkip)
                    {
                        int dist = attrPtg.Data + 1;
                        i += CountTokensToBeSkipped(ptgs, i, dist);
                        if (stack.Peek() == MissingArgEval.instance)
                        {
                            stack.Pop();
                            stack.Push(BlankEval.instance);
                        }
                        continue;
                    }
                }
                if (ptg is ControlPtg)
                {
                    // skip Parentheses, Attr, etc
                    continue;
                }
                if (ptg is MemFuncPtg || ptg is MemAreaPtg)
                {
                    // can ignore, rest of Tokens for this expression are in OK RPN order
                    continue;
                }
                if (ptg is MemErrPtg)
                {
                    continue;
                }

                ValueEval opResult;
                if (ptg is OperationPtg)
                {
                    OperationPtg optg = (OperationPtg)ptg;

                    if (optg is UnionPtg)
                    {
                        continue;
                    }

                    int         numops = optg.NumberOfOperands;
                    ValueEval[] ops    = new ValueEval[numops];

                    // storing the ops in reverse order since they are popping
                    for (int j = numops - 1; j >= 0; j--)
                    {
                        ValueEval p = (ValueEval)stack.Pop();
                        ops[j] = p;
                    }
                    //				logDebug("Invoke " + operation + " (nAgs=" + numops + ")");
                    opResult = OperationEvaluatorFactory.Evaluate(optg, ops, ec);
                }
                else
                {
                    opResult = GetEvalForPtg(ptg, ec);
                }
                if (opResult == null)
                {
                    throw new Exception("Evaluation result must not be null");
                }
                //			logDebug("push " + opResult);
                stack.Push(opResult);
                if (dbgEvaluationOutputIndent > 0)
                {
                    EVAL_LOG.Log(POILogger.INFO, dbgIndentStr + "    = " + opResult.ToString());
                }
            }

            ValueEval value = ((ValueEval)stack.Pop());

            if (stack.Count != 0)
            {
                throw new InvalidOperationException("evaluation stack not empty");
            }
            ValueEval result = DereferenceResult(value, ec.RowIndex, ec.ColumnIndex);

            if (dbgEvaluationOutputIndent > 0)
            {
                EVAL_LOG.Log(POILogger.INFO, dbgIndentStr + "finshed eval of "
                             + new CellReference(ec.RowIndex, ec.ColumnIndex).FormatAsString()
                             + ": " + result.ToString());
                dbgEvaluationOutputIndent--;
                if (dbgEvaluationOutputIndent == 1)
                {
                    // this evaluation is done, reset indent to stop logging
                    dbgEvaluationOutputIndent = -1;
                }
            } // if
            return(result);
        }