From 5bff0701fc08dcded7f38a709ad1147851e88918 Mon Sep 17 00:00:00 2001
From: Evgeniy Berlog
Date: Tue, 4 Sep 2012 21:00:41 +0000
Subject: [PATCH] resolved bugzilla ticket 53642
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1380882 13f79535-47bb-0310-9956-ffa450edef68
---
.../content/xdocs/spreadsheet/eval.xml | 32 ++++++++++-
.../hssf/usermodel/HSSFFormulaEvaluator.java | 11 ++++
.../apache/poi/hssf/usermodel/HSSFSheet.java | 26 ++++++---
.../poi/ss/formula/WorkbookEvaluator.java | 55 ++++++++++++++++++-
src/java/org/apache/poi/util/POILogger.java | 19 +++++--
.../org/apache/poi/util/SystemOutLogger.java | 4 +-
6 files changed, 127 insertions(+), 20 deletions(-)
diff --git a/src/documentation/content/xdocs/spreadsheet/eval.xml b/src/documentation/content/xdocs/spreadsheet/eval.xml
index 5ff76effb5..7cb6700196 100644
--- a/src/documentation/content/xdocs/spreadsheet/eval.xml
+++ b/src/documentation/content/xdocs/spreadsheet/eval.xml
@@ -42,7 +42,7 @@
Status
The code currently provides implementations for all the arithmatic operators.
It also provides implementations for approx. 140 built in
- functions in Excel. The framework however makes is easy to add
+ functions in Excel. The framework however makes it easy to add
implementation of new functions. See the Formula
evaluation development guide and javadocs
for details.
@@ -249,7 +249,7 @@ for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
existing workbooks with formulas. This can be done in two ways:
- 1. Re-evaluate formuals with POI's FormulaEvaluator:
+ 1. Re-evaluate formulas with POI's FormulaEvaluator:
Workbook wb = WorkbookFactory.create(new FileInputStream("workbook.xls"));
@@ -308,5 +308,33 @@ for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
+ Formula Evaluation Debugging
+ POI is not perfect and you may stumble across formula evaluation problems (Java exceptions
+ or just different results) in your special use case. To support an easy detailed analysis, a special
+ logging of the full evaluation is provided.
+ The output of this logging may be very large (depends on your EXCEL), so this logging has to be explicitly enabled
+ for each single formula evaluation. Should not be used in production - only for specific development use.
+ Example use:
+
+ // activate logging to console
+ System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
+ System.setProperty("poi.log.level", POILogger.INFO + "");
+
+ // open your file
+ Workbook wb = new HSSFWorkbook(new FileInputStream("foobar.xls"));
+ HSSFFormulaEvaluator fe = (HSSFFormulaEvaluator) wb.getCreationHelper().createFormulaEvaluator();
+
+ // get your cell
+ Cell cell = wb.getSheet(0).getRow(0).getCell(0); // just a dummy example
+
+ // perform debug output for the next evaluate-call only
+ fe.setDebugEvaluationOutputForNextEval(true);
+ evaluator.evaluateFormulaCell(cell);
+ evaluator.evaluateFormulaCell(cell); // no logging performed for this next evaluate-call
+
+ The special Logger called "POI.FormulaEval" is used (useful if you use the CommonsLogger and a detailed logging configuration).
+ The used log levels are WARN and INFO (for detailed parameter info and results) - the level are so high to allow this
+ special logging without beeing disturbed by the bunch of DEBUG log entries from other classes.
+