예제 #1
0
        public void TestEvaluateAllFails()
        {
            SXSSFWorkbook wb = new SXSSFWorkbook(5);
            SXSSFSheet    s  = wb.CreateSheet() as SXSSFSheet;

            IFormulaEvaluator eval = wb.GetCreationHelper().CreateFormulaEvaluator();

            s.CreateRow(0).CreateCell(0).CellFormula = (/*setter*/ "1+2");
            s.CreateRow(1).CreateCell(0).CellFormula = (/*setter*/ "A21");
            for (int i = 2; i < 19; i++)
            {
                s.CreateRow(i);
            }

            // Cells outside window will fail, whether referenced or not
            s.CreateRow(19).CreateCell(0).CellFormula = (/*setter*/ "A1+A2");
            s.CreateRow(20).CreateCell(0).CellFormula = (/*setter*/ "A1+A11+100");
            try
            {
                eval.EvaluateAll();
                Assert.Fail("Evaluate All shouldn't work, as some cells outside the window");
            }
            catch (RowFlushedException)
            {
                // Expected
            }


            // Inactive sheets will fail
            XSSFWorkbook xwb = new XSSFWorkbook();

            xwb.CreateSheet("Open");
            xwb.CreateSheet("Closed");

            wb.Close();
            wb = new SXSSFWorkbook(xwb, 5);
            s  = wb.GetSheet("Closed") as SXSSFSheet;
            s.FlushRows();
            s = wb.GetSheet("Open") as SXSSFSheet;
            s.CreateRow(0).CreateCell(0).CellFormula = (/*setter*/ "1+2");

            eval = wb.GetCreationHelper().CreateFormulaEvaluator();
            try
            {
                eval.EvaluateAll();
                Assert.Fail("Evaluate All shouldn't work, as sheets flushed");
            }
            catch (SheetsFlushedException) { }

            wb.Close();
        }