private static void Process(IRow row, HSSFFormulaEvaluator eval) { IEnumerator it = row.GetEnumerator(); while (it.MoveNext()) { ICell cell = (ICell)it.Current; if (cell.CellType != Npoi.Core.SS.UserModel.CellType.Formula) { continue; } FormulaRecordAggregate record = (FormulaRecordAggregate)((HSSFCell)cell).CellValueRecord; FormulaRecord r = record.FormulaRecord; Ptg[] ptgs = r.ParsedExpression; String cellRef = new CellReference(row.RowNum, cell.ColumnIndex, false, false).FormatAsString(); #if !HIDE_UNREACHABLE_CODE if (false && cellRef.Equals("BP24")) { Console.Write(cellRef); Console.WriteLine(" - has " + ptgs.Length + " ptgs:"); for (int i = 0; i < ptgs.Length; i++) { String c = ptgs[i].GetType().ToString(); Console.WriteLine("\t" + c.Substring(c.LastIndexOf('.') + 1)); } Console.WriteLine("-> " + cell.CellFormula); } #endif Npoi.Core.SS.UserModel.CellValue evalResult = eval.Evaluate(cell); Assert.IsNotNull(evalResult); } }
public void TestEvaluateSimple() { HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("TestNames.xls"); Npoi.Core.SS.UserModel.ISheet sheet = wb.GetSheetAt(0); ICell cell = sheet.GetRow(8).GetCell(0); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); Npoi.Core.SS.UserModel.CellValue cv = fe.Evaluate(cell); Assert.AreEqual(Npoi.Core.SS.UserModel.CellType.Numeric, cv.CellType); Assert.AreEqual(3.72, cv.NumberValue, 0.0); }