Thanks Josh, I found that later. But the issue is the logic for the LEFT 
or RIGHT functions always looking
for two arguments to be passed. 
arg1 = actual string
arg2 = number of chars to extract.

In my spreadsheets I have got a formula something like LEFT(celllocation) 
. They are not passing the second
argument. This is perfectly valid in excel. If no second argument  is 
passed then the return value is the first character on the left or right.
So I have modified the TextFunction class as below.

Original code:
protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short 
srcCellCol)
                                throws EvaluationException {
                        if (args.length != 2) {
                                return ErrorEval.VALUE_INVALID;
                        }
                        String arg = evaluateStringArg(args[0], 
srcCellRow, srcCellCol);
                        int index = evaluateIntArg(args[1], srcCellRow, 
srcCellCol);

                        String result;
                        if (_isLeft) {
                                result = arg.substring(0, 
Math.min(arg.length(), index));
                        } else {
                                result = arg.substring(Math.max(0, 
arg.length()-index));
                        }
                        return new StringEval(result);
                }


Modified code:
protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short 
srcCellCol)
                                throws EvaluationException {
                        /*if (args.length != 2) {
                                return ErrorEval.VALUE_INVALID;
                        }*/
 
                        if (args.length < 1 || args.length > 2) {
                                return ErrorEval.VALUE_INVALID;
                        }
                        String arg = evaluateStringArg(args[0], 
srcCellRow, srcCellCol);
                        int index = 1;
 
                        if(args.length == 2) {
                                index = evaluateIntArg(args[1], 
srcCellRow, srcCellCol);
                        }
 

                        String result;
                        if (_isLeft) {
                                result = arg.substring(0, 
Math.min(arg.length(), index));
                        } else {
                                result = arg.substring(Math.max(0, 
arg.length()-index));
                        }
                        return new StringEval(result);
                }
Regards,

Vijayakumar Gowdaman




Josh Micich <[email protected]> 
21/01/2010 05:36
Please respond to
"POI Developers List" <[email protected]>


To
[email protected]
cc

Subject
Re: Excel Function - LEFT






As far as I know LEFT *is* implemented.  You can see here at line 175:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/TextFunction.java?annotate=883197

It is registered here at line 133:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java?annotate=893030


I think this has been the case for some time (at least since version 3).

I apologise if I have misunderstood.  Perhaps you are referring to
something else besides formula evaluation.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]





---

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional 
EU corporate and regulatory disclosures.

Reply via email to