View | Details | Raw Unified | Return to bug 53642
Collapse All | Expand All

(-)src/documentation/content/xdocs/spreadsheet/eval.xml (-25 / +26 lines)
Lines 309-340 Link Here
309
      </ul>
309
      </ul>
310
    </section>
310
    </section>
311
    <section><title>Formula Evaluation Debugging</title>
311
    <section><title>Formula Evaluation Debugging</title>
312
		<p>POI is not perfect and you may stumble across formula evaluation problems (Java exceptions
312
        <p>POI is not perfect and you may stumble across formula evaluation problems (Java exceptions
313
		or just different results) in your special use case. To support an easy detailed analysis, a special
313
        or just different results) in your special use case. To support an easy detailed analysis, a special
314
		logging of the full evaluation is provided.</p>
314
        logging of the full evaluation is provided.</p>
315
		<p>The output of this logging may be very large (depends on your EXCEL), so this logging has to be explicitly enabled
315
        <p>The output of this logging may be very large (depends on your EXCEL), so this logging has to be explicitly enabled
316
		for each single formula evaluation. Should not be used in production - only for specific development use.</p>
316
        for each single formula evaluation. Should not be used in production - only for specific development use.</p>
317
		<p>Example use:</p>
317
        <p>Example use:</p>
318
		<source>
318
        <source>
319
	// activate logging to console
319
    // activate logging to console
320
	System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
320
    System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
321
	System.setProperty("poi.log.level", POILogger.INFO + "");
321
    System.setProperty("poi.log.level", POILogger.INFO + "");
322
	
322
    
323
	// open your file
323
    // open your file
324
	Workbook wb = new HSSFWorkbook(new FileInputStream("foobar.xls"));
324
    Workbook wb = new HSSFWorkbook(new FileInputStream("foobar.xls"));
325
    HSSFFormulaEvaluator fe = (HSSFFormulaEvaluator) wb.getCreationHelper().createFormulaEvaluator();
325
    FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
326
327
    // get your cell
328
    Cell cell = wb.getSheet(0).getRow(0).getCell(0);        // just a dummy example
326
329
327
	// get your cell
330
    // perform debug output for the next evaluate-call only
328
	Cell cell = wb.getSheet(0).getRow(0).getCell(0);		// just a dummy example
331
    evaluator.setDebugEvaluationOutputForNextEval(true);
332
    evaluator.evaluateFormulaCell(cell);
333
    evaluator.evaluateFormulaCell(cell);        // no logging performed for this next evaluate-call
334
        </source>
335
        <p>The special Logger called "POI.FormulaEval" is used (useful if you use the CommonsLogger and a detailed logging configuration).
336
        The used log levels are WARN and INFO (for detailed parameter info and results) - the level are so high to allow this
337
        special logging without beeing disturbed by the bunch of DEBUG log entries from other classes.</p>
338
    </section>
329
339
330
	// perform debug output for the next evaluate-call only
331
    fe.setDebugEvaluationOutputForNextEval(true);
332
	evaluator.evaluateFormulaCell(cell);
333
	evaluator.evaluateFormulaCell(cell);		// no logging performed for this next evaluate-call
334
		</source>
335
		<p>The special Logger called "POI.FormulaEval" is used (useful if you use the CommonsLogger and a detailed logging configuration).
336
		The used log levels are WARN and INFO (for detailed parameter info and results) - the level are so high to allow this
337
		special logging without beeing disturbed by the bunch of DEBUG log entries from other classes.</p>
338
	</section>
339
  </body>
340
  </body>
340
</document>
341
</document>
(-)src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java (+11 lines)
Lines 114-117 Link Here
114
     * @param cell
114
     * @param cell
115
     */
115
     */
116
    Cell evaluateInCell(Cell cell);
116
    Cell evaluateInCell(Cell cell);
117
118
    /**
119
     * Perform detailed output of formula evaluation for next evaluation only?
120
     * Is for developer use only (also developers using POI for their XLS files).
121
     * Log-Level WARN is for basic info, INFO for detailed information. These quite
122
     * high levels are used because you have to explicitly enable this specific logging.
123
	 
124
     * @param value whether to perform detailed output
125
     */
126
    void setDebugEvaluationOutputForNextEval(boolean value);
127
	
117
}
128
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (-8 / +1 lines)
Lines 389-402 Link Here
389
        _bookEvaluator.setIgnoreMissingWorkbooks(ignore);
389
        _bookEvaluator.setIgnoreMissingWorkbooks(ignore);
390
    }
390
    }
391
391
392
    /**
392
    /** {@inheritDoc} */
393
     * @param value whether perform detailed output
394
     *
395
     * Perform detailed output of formula evaluation for next evaluation only?
396
     * Is for developer use only (also developers using POI for their XLS files).
397
     * Log-Level WARN is for basic info, INFO for detailed information. These quite
398
     * high levels are used because you have to explicitly enable this specific logging.
399
     */
400
    public void setDebugEvaluationOutputForNextEval(boolean value){
393
    public void setDebugEvaluationOutputForNextEval(boolean value){
401
        _bookEvaluator.setDebugEvaluationOutputForNextEval(value);
394
        _bookEvaluator.setDebugEvaluationOutputForNextEval(value);
402
    }
395
    }
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java (+6 lines)
Lines 279-282 Link Here
279
		}
279
		}
280
		throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
280
		throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
281
	}
281
	}
282
	
283
    /** {@inheritDoc} */
284
    public void setDebugEvaluationOutputForNextEval(boolean value){
285
        _bookEvaluator.setDebugEvaluationOutputForNextEval(value);
286
    }
287
282
}
288
}

Return to bug 53642