You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Vijayakumar Gowdaman <vi...@db.com> on 2010/01/20 14:51:37 UTC

Excel Function - LEFT

One of my spreadsheet contains a excel function 'LEFT'. 

Currently I am using POI version 3.5. This function is not implemented in 
3.5.

I am planning to implement this function. Before that I would like to know 
is this function is implemented 
in any of the recent versions or it is being in the middle of development 
for the future versions.

Please let me know.

Regards,

Vijayakumar Gowdaman


---

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.

Re: Excel Function - LEFT

Posted by Vijayakumar Gowdaman <vi...@db.com>.
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 <jo...@gmail.com> 
21/01/2010 05:36
Please respond to
"POI Developers List" <de...@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.

Re: Excel Function - LEFT

Posted by Josh Micich <jo...@gmail.com>.
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