[prev in list] [next in list] [prev in thread] [next in thread] 

List:       poi-dev
Subject:    Re: Excel Function - LEFT
From:       Vijayakumar Gowdaman <vijayakumar.gowdaman () db ! com>
Date:       2010-01-22 9:20:15
Message-ID: OFE44A673A.7ED3FDBE-ON802576B3.0032B1E5-802576B3.00334762 () db ! com
[Download RAW message or body]

--=_alternative 00334762802576B3_=
Content-Type: text/plain; charset="US-ASCII"

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 <josh.micich@gmail.com> 
21/01/2010 05:36
Please respond to
"POI Developers List" <dev@poi.apache.org>


To
dev@poi.apache.org
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org





---

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.
--=_alternative 00334762802576B3_=--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic