Quantcast
Channel: Java Programming Forum - Learn Java Programming - Apache POI
Viewing all articles
Browse latest Browse all 120

Import Excel: How to get a blank, when the result of a formula is blank?

$
0
0
Hello,

I am trying to read an excel file via poi. Everything works fine except one thing. In my imported file there are two sheets. Some cells on the first page refers via a formular to cells on sheet 2, for example
Code:

=Sheet2!U3
. I only import sheet 0 and take the values from cells like this:
Code:

final ForumaleEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
final DataFormatter formatter = new DataFormatter();
final String value = formatter.format( cell, evaluator );

If Sheet2!U3 is empty, I always get "0" as value. After debugging I found out why:
WorkbookEvaluator.derefenceResult():
Code:

public static ValueEval dereferenceResult( ValueEval evaluationResult, int srcRowNum, int srcColNum )
{
    ...
    if ( value == BlankEval.instance ) {
        return NumberEval.ZERO;
        // Formulas never evaluate to blank. If a formula appears to have evlautated to blank,
        // the actual value is empty string. This can be verified with ISBLANK().
    ...
}

Is there any possibility to change this behaviour? What is about the method ISBLANK()? I could not find it anywhere? It also would be helpful, if I have access to the returned ValueEval (to do something like this:
Code:

if ( value == NumberEval.ZERO ) return null;
). But as I have seen the ValueEval is wasted during the format()-operation and only the number value of NumberEval is evaluated.

Viewing all articles
Browse latest Browse all 120

Trending Articles