コード例 #1
0
ファイル: TestWorkbookEvaluator.cs プロジェクト: 89sos98/npoi
        public void TestMissingArg()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            ISheet sheet = wb.CreateSheet("Sheet1");
            IRow row = sheet.CreateRow(0);
            ICell cell = row.CreateCell(0);
            cell.CellFormula = "1+IF(1,,)";
            HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
            CellValue cv;
            try
            {
                cv = fe.Evaluate(cell);
            }
            catch (Exception)
            {
                throw new AssertionException("Missing arg result not being handled correctly.");
            }

            Assert.AreEqual(CellType.Numeric, cv.CellType);

            // Adding blank to 1.0 gives 1.0
            Assert.AreEqual(1.0, cv.NumberValue, 0.0);

            // check with string operand
            cell.CellFormula = "\"abc\"&IF(1,,)";
            fe.NotifySetFormula(cell);
            cv = fe.Evaluate(cell);
            Assert.AreEqual(CellType.String, cv.CellType);

            // Adding blank to "abc" gives "abc"
            Assert.AreEqual("abc", cv.StringValue);

            // check CHOOSE()
            cell.CellFormula = "\"abc\"&CHOOSE(2,5,,9)";
            fe.NotifySetFormula(cell);
            cv = fe.Evaluate(cell);
            Assert.AreEqual(CellType.String, cv.CellType);

            // Adding blank to "abc" gives "abc"
            Assert.AreEqual("abc", cv.StringValue);
        }