예제 #1
0
        public void TestAddNameX()
        {
            InternalWorkbook wb = TestHSSFWorkbook.GetInternalWorkbook(new HSSFWorkbook());
            Assert.IsNotNull(wb.GetNameXPtg("ISODD", UDFFinder.DEFAULT));

            FreeRefFunction1 NotImplemented = new FreeRefFunction1();

            /**
             * register the two test UDFs in a UDF Finder, to be passed to the Evaluator
             */
            UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc", },
                    new FreeRefFunction[] { NotImplemented });
            UDFFinder udff2 = new DefaultUDFFinder(new String[] { "myFunc2", },
                    new FreeRefFunction[] { NotImplemented });
            UDFFinder udff = new AggregatingUDFFinder(udff1, udff2);
            Assert.IsNotNull(wb.GetNameXPtg("myFunc", udff));
            Assert.IsNotNull(wb.GetNameXPtg("myFunc2", udff));

            Assert.IsNull(wb.GetNameXPtg("myFunc3", udff));  // myFunc3 is unknown
        }
예제 #2
0
        public void TestInvoke()
        {
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("testNames.xls");
            ISheet sheet = wb.GetSheetAt(0);

            /**
             * register the two Test UDFs in a UDF Finder, to be passed to the Evaluator
             */
            UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc", },
                    new FreeRefFunction[] { new MyFunc(), });
            UDFFinder udff2 = new DefaultUDFFinder(new String[] { "myFunc2", },
                    new FreeRefFunction[] { new MyFunc2(), });
            UDFFinder udff = new AggregatingUDFFinder(udff1, udff2);


            IRow row = sheet.GetRow(0);
            ICell myFuncCell = row.GetCell(1); // =myFunc("_")

            ICell myFunc2Cell = row.GetCell(2); // =myFunc2("_")

            HSSFFormulaEvaluator fe = HSSFFormulaEvaluator.Create(wb, null, udff);
            Assert.AreEqual("_abc", fe.Evaluate(myFuncCell).StringValue);
            Assert.AreEqual("_abc2", fe.Evaluate(myFunc2Cell).StringValue);
        }