コード例 #1
0
        /**
         * Loops over all cells in all sheets of the supplied
         *  workbook.
         * For cells that contain formulas, their formulas are
         *  Evaluated, and the results are saved. These cells
         *  remain as formula cells.
         * For cells that do not contain formulas, no Changes
         *  are made.
         * This Is a helpful wrapper around looping over all 
         *  cells, and calling EvaluateFormulaCell on each one.
         */
        public static void EvaluateAllFormulaCells(HSSFWorkbook wb)
        {
            for (int i = 0; i < wb.NumberOfSheets; i++)
            {
                HSSFSheet sheet = wb.GetSheetAt(i);
                HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);

                for (IEnumerator rit = sheet.GetRowEnumerator(); rit.MoveNext(); )
                {
                    HSSFRow r = (HSSFRow)rit.Current;
                    evaluator.SetCurrentRow(r);

                    for (IEnumerator cit = r.GetCellEnumerator(); cit.MoveNext(); )
                    {
                        HSSFCell c = (HSSFCell)cit.Current;
                        if (c.CellType == HSSFCell.CELL_TYPE_FORMULA)
                            evaluator.EvaluateFormulaCell(c);
                    }
                }
            }
        }