Exemplo n.º 1
0
 /**
  * Takes in a String representation of a cell reference and Fills out the
  * numeric fields.
  */
 protected RefPtgBase(String cellref)
 {
     CellReference c = new CellReference(cellref);
     Row = c.Row;
     Column = c.Col;
     IsColRelative = !c.IsColAbsolute;
     IsRowRelative = !c.IsRowAbsolute;
 }
Exemplo n.º 2
0
 public Ref3DPtg(String cellref, int externIdx)
 {
     CellReference c = new CellReference(cellref);
     Row=c.Row;
     Column=c.Col;
     IsColRelative=!c.IsColAbsolute;
     IsRowRelative=!c.IsRowAbsolute;
     ExternSheetIndex=externIdx;
 }
Exemplo n.º 3
0
 public String FormatAsString()
 {
     StringBuilder sb = new StringBuilder();
     CellReference cellRefFrom = new CellReference(FirstRow, FirstColumn);
     CellReference cellRefTo = new CellReference(LastRow, LastColumn);
     sb.Append(cellRefFrom.FormatAsString());
     sb.Append(':');
     sb.Append(cellRefTo.FormatAsString());
     return sb.ToString();
 }
Exemplo n.º 4
0
        /**
         * Create an area ref from a string representation.  Sheet names containing special Chars should be
         * delimited and escaped as per normal syntax rules for formulas.<br/> 
         * The area reference must be contiguous (i.e. represent a single rectangle, not a Union of rectangles)
         */
        public AreaReference(String reference)
        {
            if (!IsContiguous(reference))
            {
                throw new ArgumentException(
                        "References passed to the AreaReference must be contiguous, " +
                        "use generateContiguous(ref) if you have non-contiguous references");
            }

            String[] parts = SeparateAreaRefs(reference);

            String part0 = parts[0];
            if (parts.Length == 1)
            {
                // TODO - probably shouldn't initialize area ref when text is really a cell ref
                // Need to fix some named range stuff to get rid of this
                _firstCell = new CellReference(part0);

                _lastCell = _firstCell;
                _isSingleCell = true;
                return;
            }
            if (parts.Length != 2)
            {
                throw new ArgumentException("Bad area ref '" + reference + "'");
            }
            String part1 = parts[1];
            if (IsPlainColumn(part0))
            {
                if (!IsPlainColumn(part1))
                {
                    throw new Exception("Bad area ref '" + reference + "'");
                }
                // Special handling for whole-column references
                // Represented internally as x$1 to x$65536
                //  which is the maximum range of rows

                bool firstIsAbs = CellReference.IsPartAbsolute(part0);
                bool lastIsAbs = CellReference.IsPartAbsolute(part1);

                int col0 = CellReference.ConvertColStringToIndex(part0);
                int col1 = CellReference.ConvertColStringToIndex(part1);

                _firstCell = new CellReference(0, col0, true, firstIsAbs);
                _lastCell = new CellReference(0xFFFF, col1, true, lastIsAbs);
                _isSingleCell = false;
                // TODO - whole row refs
            }
            else
            {
                _firstCell = new CellReference(part0);
                _lastCell = new CellReference(part1);
                _isSingleCell = part0.Equals(part1);
            }
        }
Exemplo n.º 5
0
 public override String ToString()
 {
     CellReference cr = new CellReference(Row, Column);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name).Append("[");
     sb.Append(_evaluator.GetSheetName());
     sb.Append('!');
     sb.Append(cr.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
Exemplo n.º 6
0
 public override String ToString()
 {
     CellReference cr = new CellReference(Row, Column, !IsRowRelative, !IsColRelative);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name);
     sb.Append(" [");
     sb.Append("sheetIx=").Append(ExternSheetIndex);
     sb.Append(" ! ");
     sb.Append(cr.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
Exemplo n.º 7
0
 public override String ToString()
 {
     CellReference crA = new CellReference(FirstRow, FirstColumn);
     CellReference crB = new CellReference(LastRow, LastColumn);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name).Append("[");
     sb.Append(_evaluator.GetSheetName());
     sb.Append('!');
     sb.Append(crA.FormatAsString());
     sb.Append(':');
     sb.Append(crB.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Sets the print area.
        /// </summary>
        /// <param name="sheetIndex">Zero-based sheet index (0 = First Sheet)</param>
        /// <param name="startColumn">Column to begin printarea</param>
        /// <param name="endColumn">Column to end the printarea</param>
        /// <param name="startRow">Row to begin the printarea</param>
        /// <param name="endRow">Row to end the printarea</param>
        public void SetPrintArea(int sheetIndex, int startColumn, int endColumn,
                                  int startRow, int endRow)
        {

            //using absolute references because they don't Get copied and pasted anyway
            CellReference cell = new CellReference(startRow, startColumn, true, true);
            String reference = cell.FormatAsString();

            cell = new CellReference(endRow, endColumn, true, true);
            reference = reference + ":" + cell.FormatAsString();

            SetPrintArea(sheetIndex, reference);
        }
Exemplo n.º 9
0
        /**
         * Returns a reference to every cell covered by this area
         */
        public CellReference[] GetAllReferencedCells()
        {
            // Special case for single cell reference
            if (_isSingleCell)
            {
                return new CellReference[] { _firstCell, };
            }

            // Interpolate between the two
            int minRow = Math.Min(_firstCell.Row, _lastCell.Row);
            int maxRow = Math.Max(_firstCell.Row, _lastCell.Row);
            int minCol = Math.Min(_firstCell.Col, _lastCell.Col);
            int maxCol = Math.Max(_firstCell.Col, _lastCell.Col);
            String sheetName = _firstCell.SheetName;

            ArrayList refs = new ArrayList();
            for (int row = minRow; row <= maxRow; row++)
            {
                for (int col = minCol; col <= maxCol; col++)
                {
                    CellReference ref1 = new CellReference(sheetName, row, col, _firstCell.IsRowAbsolute, _firstCell.IsColAbsolute);
                    refs.Add(ref1);
                }
            }
            return (CellReference[])refs.ToArray(typeof(CellReference));
        }
Exemplo n.º 10
0
 /**
  * Is the reference for a whole-column reference,
  *  such as C:C or D:G ?
  */
 public static bool IsWholeColumnReference(CellReference topLeft, CellReference botRight)
 {
     // These are represented as something like
     //   C$1:C$65535 or D$1:F$0
     // i.e. absolute from 1st row to 0th one
     if (topLeft.Row == 0 && topLeft.IsRowAbsolute &&
         (botRight.Row == -1 || botRight.Row == 65535) && botRight.IsRowAbsolute)
     {
         return true;
     }
     return false;
 }
Exemplo n.º 11
0
 /**
  * Creates an area ref from a pair of Cell References.
  */
 public AreaReference(CellReference topLeft, CellReference botRight)
 {
     _firstCell = topLeft;
     _lastCell = botRight;
     _isSingleCell = false;
 }
Exemplo n.º 12
0
        /**
         * @return never <c>null</c>, never {@link BlankEval}
         */
        private ValueEval EvaluateAny(EvaluationCell srcCell, int sheetIndex,
                    int rowIndex, int columnIndex, EvaluationTracker tracker)
        {

            if (srcCell == null || srcCell.CellType != HSSFCell.CELL_TYPE_FORMULA)
            {
                ValueEval result = GetValueFromNonFormulaCell(srcCell);
                tracker.AcceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result);
                return result;
            }

            FormulaCellCacheEntry cce = _cache.GetOrCreateFormulaCellEntry(srcCell);
            tracker.AcceptFormulaDependency(cce);
            IEvaluationListener evalListener = _evaluationListener;
            if (cce.GetValue() == null)
            {
                if (!tracker.StartEvaluate(cce))
                {
                    return ErrorEval.CIRCULAR_REF_ERROR;
                }

                try
                {
                    ValueEval result;

                    Ptg[] ptgs = _workbook.GetFormulaTokens(srcCell);
                    if (evalListener == null)
                    {
                        result = EvaluateFormula(sheetIndex, rowIndex, columnIndex, ptgs, tracker);
                    }
                    else
                    {
                        evalListener.OnStartEvaluate(srcCell, cce, ptgs);
                        result = EvaluateFormula(sheetIndex, rowIndex, columnIndex, ptgs, tracker);
                        evalListener.OnEndEvaluate(cce, result);
                    }

                    tracker.UpdateCacheResult(result);
                }
                finally
                {
                    tracker.EndEvaluate(cce);
                }
            }
            else
            {
                if (evalListener != null)
                {
                    evalListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, cce.GetValue());
                }
                return cce.GetValue();
            }
            if (IsDebugLogEnabled())
            {
                String sheetName = GetSheetName(sheetIndex);
                CellReference cr = new CellReference(rowIndex, columnIndex);
                LogDebug("Evaluated " + sheetName + "!" + cr.FormatAsString() + " To " + cce.GetValue().ToString());
            }
            return cce.GetValue();
        }
Exemplo n.º 13
0
 protected String FormatReferenceAsString()
 {
     // Only make cell references as needed. Memory is an issue
     CellReference cr = new CellReference(Row, Column, !IsRowRelative, !IsColRelative);
     return cr.FormatAsString();
 }
Exemplo n.º 14
0
        protected String FormatReferenceAsString()
        {
            CellReference topLeft = new CellReference(FirstRow, FirstColumn, !IsFirstRowRelative, !IsFirstColRelative);
            CellReference botRight = new CellReference(LastRow, LastColumn, !IsLastRowRelative, !IsLastColRelative);

            if (AreaReference.IsWholeColumnReference(topLeft, botRight))
            {
                return (new AreaReference(topLeft, botRight)).FormatAsString();
            }
            return topLeft.FormatAsString() + ":" + botRight.FormatAsString();
        }
 public String ToString()
 {
     StringBuilder sb = new StringBuilder(64);
     CellReference crA = new CellReference(_firstRowIndex, _firstColumnIndex, false, false);
     CellReference crB = new CellReference(_lastRowIndex, _lastColumnIndex, false, false);
     sb.Append(GetType().Name);
     sb.Append(" [").Append(crA.FormatAsString()).Append(':').Append(crB.FormatAsString()).Append("]");
     return sb.ToString();
 }
Exemplo n.º 16
0
 /**
  * @param name an 'identifier' like string (i.e. contains alphanums, and dots)
  * @return <c>null</c> if name cannot be split at a dot
  */
 private AreaReference ParseArea(String name)
 {
     int dotPos = name.IndexOf('.');
     if (dotPos < 0)
     {
         return null;
     }
     int dotCount = 1;
     while (dotCount < name.Length && name[dotPos + dotCount] == '.')
     {
         dotCount++;
         if (dotCount > 3)
         {
             // four or more consecutive dots does not convert To ':'
             return null;
         }
     }
     // This expression Is only valid as an area ref, if the LHS and RHS of the dot(s) are both
     // cell refs.  Otherwise, this expression must be a named range name
     String partA = name.Substring(0, dotPos);
     if (!IsValidCellReference(partA))
     {
         return null;
     }
     String partB = name.Substring(dotPos + dotCount);
     if (!IsValidCellReference(partB))
     {
         return null;
     }
     CellReference topLeft = new CellReference(partA);
     CellReference bottomRight = new CellReference(partB);
     return new AreaReference(topLeft, bottomRight);
 }