Пример #1
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         */
        private CellValue EvaluateFormulaCellValue(ICell cell)
        {
            if (!(cell is XSSFCell))
            {
                throw new ArgumentException("Unexpected type of cell: " + cell.GetType() + "." +
                                            " Only XSSFCells can be Evaluated.");
            }

            ValueEval eval = _bookEvaluator.Evaluate(new XSSFEvaluationCell((XSSFCell)cell));

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")");
        }
Пример #2
0
        /**
         * If cell Contains a formula, the formula is Evaluated and returned,
         * else the CellValue simply copies the appropriate cell value from
         * the cell and also its cell type. This method should be preferred over
         * EvaluateInCell() when the call should not modify the contents of the
         * original cell.
         * @param cell
         */
        public CellValue Evaluate(ICell cell)
        {
            if (cell == null)
            {
                return(null);
            }

            switch (cell.CellType)
            {
            case CellType.Boolean:
                return(CellValue.ValueOf(cell.BooleanCellValue));

            case CellType.Error:
                return(CellValue.GetError(cell.ErrorCellValue));

            case CellType.Formula:
                return(EvaluateFormulaCellValue(cell));

            case CellType.Numeric:
                return(new CellValue(cell.NumericCellValue));

            case CellType.String:
                return(new CellValue(cell.RichStringCellValue.String));

            case CellType.Blank:
                return(null);
            }
            throw new InvalidOperationException("Bad cell type (" + cell.CellType + ")");
        }
Пример #3
0
        public CellValue Evaluate(ICell cell)
        {
            if (cell == null)
            {
                return((CellValue)null);
            }
            switch (cell.CellType)
            {
            case CellType.NUMERIC:
                return(new CellValue(cell.NumericCellValue));

            case CellType.STRING:
                return(new CellValue(cell.RichStringCellValue.String));

            case CellType.FORMULA:
                return(this.EvaluateFormulaCellValue(cell));

            case CellType.BLANK:
                return((CellValue)null);

            case CellType.BOOLEAN:
                return(CellValue.ValueOf(cell.BooleanCellValue));

            case CellType.ERROR:
                return(CellValue.GetError((int)cell.ErrorCellValue));

            default:
                throw new InvalidOperationException("Bad cell type (" + (object)cell.CellType + ")");
            }
        }
Пример #4
0
        private CellValue EvaluateFormulaCellValue(ICell cell)
        {
            if (!(cell is XSSFCell))
            {
                throw new ArgumentException("Unexpected type of cell: " + (object)cell.GetType() + ". Only XSSFCells can be Evaluated.");
            }
            ValueEval valueEval = this._bookEvaluator.Evaluate((IEvaluationCell) new XSSFEvaluationCell(cell));

            if (valueEval is NumberEval)
            {
                return(new CellValue(((NumberEval)valueEval).NumberValue));
            }
            if (valueEval is BoolEval)
            {
                return(CellValue.ValueOf(((BoolEval)valueEval).BooleanValue));
            }
            if (valueEval is StringEval)
            {
                return(new CellValue(((StringEval)valueEval).StringValue));
            }
            if (valueEval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)valueEval).ErrorCode));
            }
            throw new Exception("Unexpected eval class (" + valueEval.GetType().Name + ")");
        }
Пример #5
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         * @param eval
         */
        private CellValue EvaluateFormulaCellValue(ICell cell)
        {
            ValueEval eval = _bookEvaluator.Evaluate(new HSSFEvaluationCell((HSSFCell)cell));

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new InvalidOperationException("Unexpected eval class (" + eval.GetType().Name + ")");
        }
Пример #6
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         */
        protected override CellValue EvaluateFormulaCellValue(ICell cell)
        {
            IEvaluationCell evalCell = ToEvaluationCell(cell);
            ValueEval       eval     = _bookEvaluator.Evaluate(evalCell);

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")");
        }