Example #1
0
 public Ref2DEval(RefPtg ptg, ValueEval ve)
 {
     if (ve == null)
     {
         throw new ArgumentException("ve must not be null");
     }
     if (false && ptg == null)
     { // TODO - fix dodgy code in MultiOperandNumericFunction
         throw new ArgumentException("ptg must not be null");
     }
     value = ve;
     _delegate = ptg;
 }
Example #2
0
 /**
  * @return <c>true</c> if this Ptg needed to be changed
  */
 private Ptg AdjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx)
 {
     if (ptg is RefPtg)
     {
         if (currentExternSheetIx != _externSheetIndex)
         {
             // local refs on other sheets are unaffected
             return(null);
         }
         RefPtg rptg = (RefPtg)ptg;
         return(RowMoveRefPtg(rptg));
     }
     if (ptg is Ref3DPtg)
     {
         Ref3DPtg rptg = (Ref3DPtg)ptg;
         if (_externSheetIndex != rptg.ExternSheetIndex)
         {
             // only move 3D refs that refer to the sheet with cells being moved
             // (currentExternSheetIx is irrelevant)
             return(null);
         }
         return(RowMoveRefPtg(rptg));
     }
     if (ptg is Area2DPtgBase)
     {
         if (currentExternSheetIx != _externSheetIndex)
         {
             // local refs on other sheets are unaffected
             return(ptg);
         }
         return(RowMoveAreaPtg((Area2DPtgBase)ptg));
     }
     if (ptg is Area3DPtg)
     {
         Area3DPtg aptg = (Area3DPtg)ptg;
         if (_externSheetIndex != aptg.ExternSheetIndex)
         {
             // only move 3D refs that refer to the sheet with cells being moved
             // (currentExternSheetIx is irrelevant)
             return(null);
         }
         return(RowMoveAreaPtg(aptg));
     }
     return(null);
 }
Example #3
0
        /**
         *
         * @param sheetIden may be <code>null</code>
         * @param part1
         * @param part2 may be <code>null</code>
         */
        private ParseNode CreateAreaRefParseNode(SheetIdentifier sheetIden, SimpleRangePart part1,
                SimpleRangePart part2)
        {
            int extIx;
            if (sheetIden == null)
            {
                extIx = Int32.MinValue;
            }
            else
            {
                String sName = sheetIden.SheetID.Name;
                if (sheetIden.BookName == null)
                {
                    extIx = book.GetExternalSheetIndex(sName);
                }
                else
                {
                    extIx = book.GetExternalSheetIndex(sheetIden.BookName, sName);
                }
            }
            Ptg ptg;
            if (part2 == null)
            {
                CellReference cr = part1.getCellReference();
                if (sheetIden == null)
                {
                    ptg = new RefPtg(cr);
                }
                else
                {
                    ptg = new Ref3DPtg(cr, extIx);
                }
            }
            else
            {
                AreaReference areaRef = CreateAreaRef(part1, part2);

                if (sheetIden == null)
                {
                    ptg = new AreaPtg(areaRef);
                }
                else
                {
                    ptg = new Area3DPtg(areaRef, extIx);
                }
            }
            return new ParseNode(ptg);
        }
Example #4
0
        /**
         * Creates a non shared formula from the shared formula counterpart<br/>
         *
         * Perhaps this functionality could be implemented in terms of the raw
         * byte array inside {@link Formula}.
         */
        public static Ptg[] ConvertSharedFormulas(Ptg[] ptgs, int formulaRow, int formulaColumn)
        {
            Ptg[] newPtgStack = new Ptg[ptgs.Length];

            for (int k = 0; k < ptgs.Length; k++)
            {
                Ptg ptg = ptgs[k];
                byte originalOperandClass = unchecked((byte)-1);
                if (!ptg.IsBaseToken)
                {
                    originalOperandClass = ptg.PtgClass;
                }
                if (ptg is RefPtgBase)
                {
                    RefPtgBase refNPtg = (RefPtgBase)ptg;
                    ptg = new RefPtg(FixupRelativeRow(formulaRow, refNPtg.Row, refNPtg.IsRowRelative),
                                         FixupRelativeColumn(formulaColumn, refNPtg.Column, refNPtg.IsColRelative),
                                         refNPtg.IsRowRelative,
                                         refNPtg.IsColRelative);
                    ptg.PtgClass = originalOperandClass;
                }
                else if (ptg is AreaPtgBase)
                {
                    AreaPtgBase areaNPtg = (AreaPtgBase)ptg;
                    ptg = new AreaPtg(FixupRelativeRow(formulaRow, areaNPtg.FirstRow, areaNPtg.IsFirstRowRelative),
                                    FixupRelativeRow(formulaRow, areaNPtg.LastRow, areaNPtg.IsLastRowRelative),
                                    FixupRelativeColumn(formulaColumn, areaNPtg.FirstColumn, areaNPtg.IsFirstColRelative),
                                    FixupRelativeColumn(formulaColumn, areaNPtg.LastColumn, areaNPtg.IsLastColRelative),
                                    areaNPtg.IsFirstRowRelative,
                                    areaNPtg.IsLastRowRelative,
                                    areaNPtg.IsFirstColRelative,
                                    areaNPtg.IsLastColRelative);
                    ptg.PtgClass = originalOperandClass;
                }
                else if (ptg is OperandPtg)
                {
                    // Any subclass of OperandPtg is mutable, so it's safest to not share these instances.
                    ptg = ((OperandPtg)ptg).Copy();
                }
                else
                {
                    // all other Ptgs are immutable and can be shared
                }
                newPtgStack[k] = ptg;
            }
            return newPtgStack;
        }
Example #5
0
        public LazyRefEval(RefPtg ptg, SheetRefEvaluator sre)
            : base(ptg.Row, ptg.Column)
        {

            _evaluator = sre;
        }
        /**
         * Creates a non shared formula from the shared formula 
         * counter part
         */
        public static Ptg[] ConvertSharedFormulas(Ptg[] ptgs, int formulaRow, int formulaColumn)
        {
            if (false)
            {
                /*
                 * TODO - (May-2008) Stop Converting relative ref Ptgs in shared formula records. 
                 * If/when POI Writes out the workbook, this conversion makes an Unnecessary diff in the BIFF records.
                 * Disabling this code breaks one existing junit.
                 * Some fix-up will be required to make Ptg.ToFormulaString(HSSFWorkbook) work properly.
                 * That method will need 2 extra params: rowIx and colIx.
                 */
                return ptgs;
            }
            Ptg[] newPtgStack = new Ptg[ptgs.Length];

            if (ptgs != null)
                for (int k = 0; k < ptgs.Length; k++)
                {
                    Ptg ptg = (Ptg)ptgs[k];
                    byte originalOperandClass = unchecked((byte)-1);
                    if (!ptg.IsBaseToken)
                    {
                        originalOperandClass = ptg.PtgClass;
                    }
                    if (ptg is RefNPtg)
                    {
                        RefNPtg refNPtg = (RefNPtg)ptg;
                        ptg = new RefPtg(FixupRelativeRow(formulaRow, refNPtg.Row, refNPtg.IsRowRelative),
                                               FixupRelativeColumn(formulaColumn, refNPtg.Column, refNPtg.IsColRelative),
                                               refNPtg.IsRowRelative,
                                               refNPtg.IsColRelative);
                    }
                    else if (ptg is AreaNPtg)
                    {
                        AreaNPtg areaNPtg = (AreaNPtg)ptg;
                        ptg = new AreaPtg(FixupRelativeRow(formulaRow, areaNPtg.FirstRow, areaNPtg.IsFirstRowRelative),
                                          FixupRelativeRow(formulaRow, areaNPtg.LastRow, areaNPtg.IsLastRowRelative),
                                          FixupRelativeColumn(formulaColumn, areaNPtg.FirstColumn, areaNPtg.IsFirstColRelative),
                                          FixupRelativeColumn(formulaColumn, areaNPtg.LastColumn, areaNPtg.IsLastColRelative),
                                          areaNPtg.IsFirstRowRelative,
                                          areaNPtg.IsLastRowRelative,
                                          areaNPtg.IsFirstColRelative,
                                          areaNPtg.IsLastColRelative);
                    }
                    if (!ptg.IsBaseToken)
                    {
                        ptg.PtgClass=originalOperandClass;
                    }

                    newPtgStack[k] = ptg;
                }
            return newPtgStack;
        }