Contributing

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Contributing

Glauco Vinicius Scheffel
Hi Amol,

Thanks a lot, it Work with the call to evaluator.setCurrentRow(row);


My friend used the current version in the scratchpad (I copy him at the cc field), where he find the following functions already implement Abs, Acos, Acosh, And, Asin, Asinh, Atan, Atan, Atanh, Cos, Cosh, Degrees, Dollar, Even, Exp, Int, Ln, Log, Log10, Odd, Or, Power, Radians, Sign, Sin, Sinh, Tan e Tanh.

He is going to join the project to implement the function Sum and Average (and others to the financial area).

But before any contribution, he would like to know. Is the code made like expected? He has to sign any agreement?

[  ]´s

-----Mensagem original-----
De: Amol Deshmukh [mailto:[hidden email]]
Enviada em: segunda-feira, 30 de maio de 2005 16:55
Para: POI Developers List
Assunto: Re: RES: cvs commit: jakarta-poi/src/documentation/content/xdocs/hssf eval.xml

Hi,

you need to call:
        evaluator.setCurrentRow(row);
before :
        HSSFFormulaEvaluator.CellValue cellValue =
evaluator.evaluate(cell);


Also, check your formula, you are referring to Cell
"A0" which does not exist, since excel numbering
starts from 1 :)

So I think the formula that you intended to use should
be "B1+B2" instead of "A1+A0" since:

row=0 & col=1 => B1
row=1 & col=1 => B2
row=2 & col=1 => B3



I tried your program with the above changes and it
works fine.

On a related note, you shouldnt have to call
cell.setCellType(..), it is handled internally
depending on the type of argument to setCellValue(..).
(Although, calling setCellType(..) will not cause a
problem if called with the correct arg value.)


Regards,
~ amol





--- Glauco Vinicius Scheffel
<[hidden email]> wrote:

> Hi,
>
> I´m a subscriber of the POI list, to follow the
> product evolution since we use it in our GED tool. A
> friend o mine ask for assistance in using formulas
> but I never did this if POI (I just use to extract
> data). Do you know how can send his help request for
> the POI developers?
>
>
> TIA
>
>
>        
>                    H E L P    R E Q U E S T      I S
>   B E L O W
>
>
>
> Hi !
>
> I need a little assistence. I'm just trying to
> evaluate a simple formula using HSSF component. Take
> a look
> in the code below:
>
> import org.apache.poi.hssf.usermodel.HSSFCell;
> import
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
> import org.apache.poi.hssf.usermodel.HSSFRow;
> import org.apache.poi.hssf.usermodel.HSSFSheet;
> import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> import org.apache.poi.hssf.util.CellReference;
>
> /**
>  * Simple test class.
>  * @version 1.0
>  */
> public class Formula {
>    
>     private HSSFWorkbook wb;
>     private HSSFSheet sheet;
>    
>     public Formula(){
>         this.wb = new HSSFWorkbook();
>         this.createSheet();
>     }
>
>     private void createSheet(){
>         this.sheet = this.wb.createSheet();
>         this.createCells();
>     }
>    
>     private void createCells(){
>         HSSFRow r = null;
>         HSSFCell c = null;
>        
>         HSSFCell formula = null;
>        
>         this.sheet.createRow(0);
>         this.sheet.createRow(1);
>         this.sheet.createRow(2);
>        
>         c =
> this.sheet.getRow(0).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
>        
>
this.sheet.getRow(0).getCell((short)1).setCellValue(10);
>         c =
> this.sheet.getRow(1).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
>        
>
this.sheet.getRow(1).getCell((short)1).setCellValue(10);

>         c =
> this.sheet.getRow(2).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_FORMULA);
>         c.setCellFormula("A0+A1");
>        
>         HSSFFormulaEvaluator evaluator = new
> HSSFFormulaEvaluator(this.sheet,this.wb);
>        
>         CellReference cellReference = new
> CellReference(2,1);
>         HSSFRow row =
> sheet.getRow(cellReference.getRow());
>         HSSFCell cell =
> row.getCell(cellReference.getCol());
>      
>         if (cell == null){
>             System.out.println("its null");
>         } else if (cell.getCellType() ==
> HSSFCell.CELL_TYPE_FORMULA) {
>             System.out.println("Formula : "+
> cell.getCellFormula());
>         }
>        
>         HSSFFormulaEvaluator.CellValue cellValue =
> evaluator.evaluate(cell);
>
>        
> System.out.println(cellValue.getNumberValue());
>     }
>    
>     public static void main(String args[]){
>         Formula f = new Formula();
>     }
>
> }
>
>
> My program aborts with a NullPointerException:
> Formula : A0+A1
> java.lang.NullPointerException
> at
>
org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFormulaEvaluator.java:281)
> at
>
org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEvaluator.java:181)
> at
>
com.datasul.dcl.formula.test.Formula.createCells(Formula.java:67)
> at
>
com.datasul.dcl.formula.test.Formula.createSheet(Formula.java:30)
> at
>
com.datasul.dcl.formula.test.Formula.<init>(Formula.java:25)
> at
>
com.datasul.dcl.formula.test.Formula.main(Formula.java:73)

> Exception in thread "main"
>
> Did I make any mistake ? Can somebody help me ?
>
> Thanks in advance !
>
>
>
>
> -----Mensagem original-----
> De: [hidden email] [mailto:[hidden email]]
> Enviada em: terça-feira, 24 de maio de 2005 11:23
> Para: [hidden email]
> Assunto: cvs commit:
> jakarta-poi/src/documentation/content/xdocs/hssf
> eval.xml
>
> avik        2005/05/24 07:23:03
>
>   Modified:    src/documentation/content/xdocs/hssf
> eval.xml
>   Log:
>   small update
>  
>   Revision  Changes    Path
>   1.3       +4 -5    
>
jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml
>  
>   Index: eval.xml
>  
>
===================================================================
>   RCS file:
>
/home/cvs/jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml,v

>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- eval.xml 19 May 2005 10:36:06 -0000 1.2
>   +++ eval.xml 24 May 2005 14:23:03 -0000 1.3
>   @@ -15,11 +15,10 @@
>     formulas in Excels sheets read-in, or created
> in POI. This document explains
>     how to use the API to evaluate your formulas.
>
>     </p>
>   - <warning> This code currently lives in
> Bugzilla as
>   - <link
>
href="http://issues.apache.org/bugzilla/show_bug.cgi?id=34828">

>
>   - bug 34828 </link>. It is expected to land in
> POI CVS in the scratchpad
>   - area soon.
>   - </warning>
>   + <note> This code currently lives the
> scratchpad area of the POI CVS repository.
>   + Ensure that you have the scratchpad jar or
> the scratchpad build area in your
>   + classpath before experimenting with this
> code.
>   + </note>
>     </section>
>     <section><title>Status</title>
>     <p> The code currently provides
> implementations for all the arithmatic operators.
>  
>  
>  
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [hidden email]
> Mailing List:  
> http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project:
> http://jakarta.apache.org/poi/
>
>
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Reply | Threaded
Open this post in threaded view
|

RES: Contributing

Glauco Vinicius Scheffel
Here is the code for Average and Sum


/*
 * Created on May 15, 2005
 *
 */
package org.apache.poi.hssf.record.formula.functions;

import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;

public class Sum extends NumericFunction {
    private static final ValueEvalToNumericXlator NUM_XLATOR =
        new ValueEvalToNumericXlator((short)
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
                | ValueEvalToNumericXlator.STRING_IS_PARSED
                ));

    protected ValueEvalToNumericXlator getXlator() {
        return NUM_XLATOR;
    }
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
        double sum             = 0;
        ValueEval retval = null;
       
       
        for (int i = 0; i < operands.length; i++) {
            ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
            if (ve instanceof NumericValueEval) {
                NumericValueEval ne = (NumericValueEval) ve;
                sum += ne.getNumberValue();
            }
            else if (ve instanceof BlankEval) {
                // do nothing
            }
            else {
                retval = ErrorEval.NUM_ERROR;
            }
        }
       
        if (retval == null) {
            retval = (Double.isNaN(sum)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(sum);
        }
        return retval;
    }

   
}


/*
 * Created on May 15, 2005
 *
 */
package org.apache.poi.hssf.record.formula.functions;

import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;

/**
 * @author
 *
 */
public class Average extends NumericFunction {
    private static final ValueEvalToNumericXlator NUM_XLATOR =
        new ValueEvalToNumericXlator((short)
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
                | ValueEvalToNumericXlator.STRING_IS_PARSED
                ));

    protected ValueEvalToNumericXlator getXlator() {
        return NUM_XLATOR;
    }
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
        double sum             = 0;
        double numberElements  = operands.length;
        ValueEval retval = null;
       
       
        for (int i = 0; i < operands.length; i++) {
            ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
            if (ve instanceof NumericValueEval) {
                NumericValueEval ne = (NumericValueEval) ve;
                sum += ne.getNumberValue();
            }
            else if (ve instanceof BlankEval) {
                // doesn't count a blank cell to get the average
                // this is right?
                numberElements--;
            }
            else {
                retval = ErrorEval.NUM_ERROR;
            }
        }
       
        if (retval == null) {
            retval = (Double.isNaN(sum)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(sum / numberElements);
        }
        return retval;
    }

   
}

-----Mensagem original-----
De: Glauco Vinicius Scheffel
Enviada em: quarta-feira, 1 de junho de 2005 10:44
Para: POI Developers List
Cc: Michel Bertrand
Assunto: Contributing

Hi Amol,

Thanks a lot, it Work with the call to evaluator.setCurrentRow(row);


My friend used the current version in the scratchpad (I copy him at the cc field), where he find the following functions already implement Abs, Acos, Acosh, And, Asin, Asinh, Atan, Atan, Atanh, Cos, Cosh, Degrees, Dollar, Even, Exp, Int, Ln, Log, Log10, Odd, Or, Power, Radians, Sign, Sin, Sinh, Tan e Tanh.

He is going to join the project to implement the function Sum and Average (and others to the financial area).

But before any contribution, he would like to know. Is the code made like expected? He has to sign any agreement?

[  ]´s

-----Mensagem original-----
De: Amol Deshmukh [mailto:[hidden email]]
Enviada em: segunda-feira, 30 de maio de 2005 16:55
Para: POI Developers List
Assunto: Re: RES: cvs commit: jakarta-poi/src/documentation/content/xdocs/hssf eval.xml

Hi,

you need to call:
        evaluator.setCurrentRow(row);
before :
        HSSFFormulaEvaluator.CellValue cellValue =
evaluator.evaluate(cell);


Also, check your formula, you are referring to Cell
"A0" which does not exist, since excel numbering
starts from 1 :)

So I think the formula that you intended to use should
be "B1+B2" instead of "A1+A0" since:

row=0 & col=1 => B1
row=1 & col=1 => B2
row=2 & col=1 => B3



I tried your program with the above changes and it
works fine.

On a related note, you shouldnt have to call
cell.setCellType(..), it is handled internally
depending on the type of argument to setCellValue(..).
(Although, calling setCellType(..) will not cause a
problem if called with the correct arg value.)


Regards,
~ amol





--- Glauco Vinicius Scheffel
<[hidden email]> wrote:

> Hi,
>
> I´m a subscriber of the POI list, to follow the
> product evolution since we use it in our GED tool. A
> friend o mine ask for assistance in using formulas
> but I never did this if POI (I just use to extract
> data). Do you know how can send his help request for
> the POI developers?
>
>
> TIA
>
>
>        
>                    H E L P    R E Q U E S T      I S
>   B E L O W
>
>
>
> Hi !
>
> I need a little assistence. I'm just trying to
> evaluate a simple formula using HSSF component. Take
> a look
> in the code below:
>
> import org.apache.poi.hssf.usermodel.HSSFCell;
> import
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
> import org.apache.poi.hssf.usermodel.HSSFRow;
> import org.apache.poi.hssf.usermodel.HSSFSheet;
> import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> import org.apache.poi.hssf.util.CellReference;
>
> /**
>  * Simple test class.
>  * @version 1.0
>  */
> public class Formula {
>    
>     private HSSFWorkbook wb;
>     private HSSFSheet sheet;
>    
>     public Formula(){
>         this.wb = new HSSFWorkbook();
>         this.createSheet();
>     }
>
>     private void createSheet(){
>         this.sheet = this.wb.createSheet();
>         this.createCells();
>     }
>    
>     private void createCells(){
>         HSSFRow r = null;
>         HSSFCell c = null;
>        
>         HSSFCell formula = null;
>        
>         this.sheet.createRow(0);
>         this.sheet.createRow(1);
>         this.sheet.createRow(2);
>        
>         c =
> this.sheet.getRow(0).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
>        
>
this.sheet.getRow(0).getCell((short)1).setCellValue(10);
>         c =
> this.sheet.getRow(1).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
>        
>
this.sheet.getRow(1).getCell((short)1).setCellValue(10);

>         c =
> this.sheet.getRow(2).createCell((short)1);
>         c.setCellType(HSSFCell.CELL_TYPE_FORMULA);
>         c.setCellFormula("A0+A1");
>        
>         HSSFFormulaEvaluator evaluator = new
> HSSFFormulaEvaluator(this.sheet,this.wb);
>        
>         CellReference cellReference = new
> CellReference(2,1);
>         HSSFRow row =
> sheet.getRow(cellReference.getRow());
>         HSSFCell cell =
> row.getCell(cellReference.getCol());
>      
>         if (cell == null){
>             System.out.println("its null");
>         } else if (cell.getCellType() ==
> HSSFCell.CELL_TYPE_FORMULA) {
>             System.out.println("Formula : "+
> cell.getCellFormula());
>         }
>        
>         HSSFFormulaEvaluator.CellValue cellValue =
> evaluator.evaluate(cell);
>
>        
> System.out.println(cellValue.getNumberValue());
>     }
>    
>     public static void main(String args[]){
>         Formula f = new Formula();
>     }
>
> }
>
>
> My program aborts with a NullPointerException:
> Formula : A0+A1
> java.lang.NullPointerException
> at
>
org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFormulaEvaluator.java:281)
> at
>
org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEvaluator.java:181)
> at
>
com.datasul.dcl.formula.test.Formula.createCells(Formula.java:67)
> at
>
com.datasul.dcl.formula.test.Formula.createSheet(Formula.java:30)
> at
>
com.datasul.dcl.formula.test.Formula.<init>(Formula.java:25)
> at
>
com.datasul.dcl.formula.test.Formula.main(Formula.java:73)

> Exception in thread "main"
>
> Did I make any mistake ? Can somebody help me ?
>
> Thanks in advance !
>
>
>
>
> -----Mensagem original-----
> De: [hidden email] [mailto:[hidden email]]
> Enviada em: terça-feira, 24 de maio de 2005 11:23
> Para: [hidden email]
> Assunto: cvs commit:
> jakarta-poi/src/documentation/content/xdocs/hssf
> eval.xml
>
> avik        2005/05/24 07:23:03
>
>   Modified:    src/documentation/content/xdocs/hssf
> eval.xml
>   Log:
>   small update
>  
>   Revision  Changes    Path
>   1.3       +4 -5    
>
jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml
>  
>   Index: eval.xml
>  
>
===================================================================
>   RCS file:
>
/home/cvs/jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml,v

>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- eval.xml 19 May 2005 10:36:06 -0000 1.2
>   +++ eval.xml 24 May 2005 14:23:03 -0000 1.3
>   @@ -15,11 +15,10 @@
>     formulas in Excels sheets read-in, or created
> in POI. This document explains
>     how to use the API to evaluate your formulas.
>
>     </p>
>   - <warning> This code currently lives in
> Bugzilla as
>   - <link
>
href="http://issues.apache.org/bugzilla/show_bug.cgi?id=34828">

>
>   - bug 34828 </link>. It is expected to land in
> POI CVS in the scratchpad
>   - area soon.
>   - </warning>
>   + <note> This code currently lives the
> scratchpad area of the POI CVS repository.
>   + Ensure that you have the scratchpad jar or
> the scratchpad build area in your
>   + classpath before experimenting with this
> code.
>   + </note>
>     </section>
>     <section><title>Status</title>
>     <p> The code currently provides
> implementations for all the arithmatic operators.
>  
>  
>  
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [hidden email]
> Mailing List:  
> http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project:
> http://jakarta.apache.org/poi/
>
>
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply | Threaded
Open this post in threaded view
|

RE: Contributing

Amol Deshmukh
In reply to this post by Glauco Vinicius Scheffel
Glauco,

Thanks for the thanks :)

* About legal issues:
I do not know since I am not an official developer for
POI. FormulaEvaluator is a free and open source contribution.
(Perhaps Andy or others can better answer that question?)

* Update on formula evaluator:
I have added a new patch in bugzilla for some more
function implementations (that include Average and Sum),
However, any contributions for the unimplemented
functions are always welcome. For contributions, you can
simply create an issue in bugzilla, mark it as a PATCH
and add your code-contribution as an attachment.
  If you plan on contributing any of the functions,
it would be great if we could coordinate the efforts
so that we dont end up implementing the same functions :)

* Contributing:
For more info on how to contribute, please refer
to the information on "Contributing" on the project
home page.

Thanks & Regards,
~ amol






> -----Original Message-----
> From: Glauco Vinicius Scheffel [mailto:[hidden email]]
> Sent: Wednesday, June 01, 2005 9:44 AM
> To: POI Developers List
> Cc: Michel Bertrand
> Subject: Contributing
>
>
> Hi Amol,
>
> Thanks a lot, it Work with the call to evaluator.setCurrentRow(row);
>
>
> My friend used the current version in the scratchpad (I copy
> him at the cc field), where he find the following functions
> already implement Abs, Acos, Acosh, And, Asin, Asinh, Atan,
> Atan, Atanh, Cos, Cosh, Degrees, Dollar, Even, Exp, Int, Ln,
> Log, Log10, Odd, Or, Power, Radians, Sign, Sin, Sinh, Tan e Tanh.
>
> He is going to join the project to implement the function Sum
> and Average (and others to the financial area).
>
> But before any contribution, he would like to know. Is the
> code made like expected? He has to sign any agreement?
>
> [  ]´s
>
> -----Mensagem original-----
> De: Amol Deshmukh [mailto:[hidden email]]
> Enviada em: segunda-feira, 30 de maio de 2005 16:55
> Para: POI Developers List
> Assunto: Re: RES: cvs commit:
> jakarta-poi/src/documentation/content/xdocs/hssf eval.xml
>
> Hi,
>
> you need to call:
>         evaluator.setCurrentRow(row);
> before :
>         HSSFFormulaEvaluator.CellValue cellValue =
> evaluator.evaluate(cell);
>
>
> Also, check your formula, you are referring to Cell
> "A0" which does not exist, since excel numbering
> starts from 1 :)
>
> So I think the formula that you intended to use should
> be "B1+B2" instead of "A1+A0" since:
>
> row=0 & col=1 => B1
> row=1 & col=1 => B2
> row=2 & col=1 => B3
>
>
>
> I tried your program with the above changes and it
> works fine.
>
> On a related note, you shouldnt have to call
> cell.setCellType(..), it is handled internally
> depending on the type of argument to setCellValue(..).
> (Although, calling setCellType(..) will not cause a
> problem if called with the correct arg value.)
>
>
> Regards,
> ~ amol
>
>
>
>
>
> --- Glauco Vinicius Scheffel
> <[hidden email]> wrote:
>
> > Hi,
> >
> > I´m a subscriber of the POI list, to follow the
> > product evolution since we use it in our GED tool. A
> > friend o mine ask for assistance in using formulas
> > but I never did this if POI (I just use to extract
> > data). Do you know how can send his help request for
> > the POI developers?
> >
> >
> > TIA
> >
> >
> >        
> >                    H E L P    R E Q U E S T      I S
> >   B E L O W
> >
> >
> >
> > Hi !
> >
> > I need a little assistence. I'm just trying to
> > evaluate a simple formula using HSSF component. Take
> > a look
> > in the code below:
> >
> > import org.apache.poi.hssf.usermodel.HSSFCell;
> > import
> > org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
> > import org.apache.poi.hssf.usermodel.HSSFRow;
> > import org.apache.poi.hssf.usermodel.HSSFSheet;
> > import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> > import org.apache.poi.hssf.util.CellReference;
> >
> > /**
> >  * Simple test class.
> >  * @version 1.0
> >  */
> > public class Formula {
> >    
> >     private HSSFWorkbook wb;
> >     private HSSFSheet sheet;
> >    
> >     public Formula(){
> >         this.wb = new HSSFWorkbook();
> >         this.createSheet();
> >     }
> >
> >     private void createSheet(){
> >         this.sheet = this.wb.createSheet();
> >         this.createCells();
> >     }
> >    
> >     private void createCells(){
> >         HSSFRow r = null;
> >         HSSFCell c = null;
> >        
> >         HSSFCell formula = null;
> >        
> >         this.sheet.createRow(0);
> >         this.sheet.createRow(1);
> >         this.sheet.createRow(2);
> >        
> >         c =
> > this.sheet.getRow(0).createCell((short)1);
> >         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
> >        
> >
> this.sheet.getRow(0).getCell((short)1).setCellValue(10);
> >         c =
> > this.sheet.getRow(1).createCell((short)1);
> >         c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
> >        
> >
> this.sheet.getRow(1).getCell((short)1).setCellValue(10);
> >         c =
> > this.sheet.getRow(2).createCell((short)1);
> >         c.setCellType(HSSFCell.CELL_TYPE_FORMULA);
> >         c.setCellFormula("A0+A1");
> >        
> >         HSSFFormulaEvaluator evaluator = new
> > HSSFFormulaEvaluator(this.sheet,this.wb);
> >        
> >         CellReference cellReference = new
> > CellReference(2,1);
> >         HSSFRow row =
> > sheet.getRow(cellReference.getRow());
> >         HSSFCell cell =
> > row.getCell(cellReference.getCol());
> >      
> >         if (cell == null){
> >             System.out.println("its null");
> >         } else if (cell.getCellType() ==
> > HSSFCell.CELL_TYPE_FORMULA) {
> >             System.out.println("Formula : "+
> > cell.getCellFormula());
> >         }
> >        
> >         HSSFFormulaEvaluator.CellValue cellValue =
> > evaluator.evaluate(cell);
> >
> >        
> > System.out.println(cellValue.getNumberValue());
> >     }
> >    
> >     public static void main(String args[]){
> >         Formula f = new Formula();
> >     }
> >
> > }
> >
> >
> > My program aborts with a NullPointerException:
> > Formula : A0+A1
> > java.lang.NullPointerException
> > at
> >
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEva
> luate(HSSFFormulaEvaluator.java:281)
> > at
> >
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HS
> SFFormulaEvaluator.java:181)
> > at
> >
> com.datasul.dcl.formula.test.Formula.createCells(Formula.java:67)
> > at
> >
> com.datasul.dcl.formula.test.Formula.createSheet(Formula.java:30)
> > at
> >
> com.datasul.dcl.formula.test.Formula.<init>(Formula.java:25)
> > at
> >
> com.datasul.dcl.formula.test.Formula.main(Formula.java:73)
> > Exception in thread "main"
> >
> > Did I make any mistake ? Can somebody help me ?
> >
> > Thanks in advance !
> >
> >
> >
> >
> > -----Mensagem original-----
> > De: [hidden email] [mailto:[hidden email]]
> > Enviada em: terça-feira, 24 de maio de 2005 11:23
> > Para: [hidden email]
> > Assunto: cvs commit:
> > jakarta-poi/src/documentation/content/xdocs/hssf
> > eval.xml
> >
> > avik        2005/05/24 07:23:03
> >
> >   Modified:    src/documentation/content/xdocs/hssf
> > eval.xml
> >   Log:
> >   small update
> >  
> >   Revision  Changes    Path
> >   1.3       +4 -5    
> >
> jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml
> >  
> >   Index: eval.xml
> >  
> >
> ===================================================================
> >   RCS file:
> >
> /home/cvs/jakarta-poi/src/documentation/content/xdocs/hssf/eval.xml,v
> >   retrieving revision 1.2
> >   retrieving revision 1.3
> >   diff -u -r1.2 -r1.3
> >   --- eval.xml 19 May 2005 10:36:06 -0000 1.2
> >   +++ eval.xml 24 May 2005 14:23:03 -0000 1.3
> >   @@ -15,11 +15,10 @@
> >     formulas in Excels sheets
> read-in, or created
> > in POI. This document explains
> >     how to use the API to evaluate
> your formulas.
> >
> >     </p>
> >   - <warning> This code currently lives in
> > Bugzilla as
> >   - <link
> >
> href="http://issues.apache.org/bugzilla/show_bug.cgi?id=34828">
> >
> >   - bug 34828 </link>. It is
> expected to land in
> > POI CVS in the scratchpad
> >   - area soon.
> >   - </warning>
> >   + <note> This code currently lives the
> > scratchpad area of the POI CVS repository.
> >   + Ensure that you have the
> scratchpad jar or
> > the scratchpad build area in your
> >   + classpath before experimenting with this
> > code.
> >   + </note>
> >     </section>
> >     <section><title>Status</title>
> >     <p> The code currently provides
> > implementations for all the arithmatic operators.
> >  
> >  
> >  
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [hidden email]
> > Mailing List:  
> > http://jakarta.apache.org/site/mail2.html#poi
> > The Apache Jakarta POI Project:
> > http://jakarta.apache.org/poi/
> >
> >
> === message truncated ===
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/