You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Ruben Garcia <ru...@asi-soluciones.com> on 2012/11/20 18:25:20 UTC

Setting a defined user formula Error

Good afternoon,

I'm trying to set a formula set in my ExcelSheet template, which 
contains a VB function to do some calculations. I followed this example 
http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java 
but when I create the ExcelSheet, the Cell where I set the formula 
doesn't show the value, it shows a "name error". Here is my code:

                 Workbook wb2 = WorkbookFactory.create(fis);
                 String[] functionNames = {"Calculo_VPS"};
                  FreeRefFunction[] functionImpls = {new FreeRefFunction() {

                         @Override
                         public ValueEval evaluate(ValueEval[] arg0,
                                 OperationEvaluationContext arg1) {
                              // don't care about the returned result. 
we are not going to evaluate BDP
                                return ErrorEval.NA;

                         }
                      }};

                      UDFFinder udfToolpack = new 
DefaultUDFFinder(functionNames,
                      functionImpls);

                      // register the user-defined function in the workbook
                      wb2.addToolPack(udfToolpack);

row2.createCell(19).setCellFormula(formulaC19);
                 wb2.setForceFormulaRecalculation(true);

I've also tried with this one:
row2.createCell(19).setCellType(HSSFCell.CELL_TYPE_FORMULA);
row2.getCell(19)..setCellFormula(formulaC19);

Could anyone help me with this?
--

Re: Setting a defined user formula Error

Posted by Ruben Garcia <ru...@asi-soluciones.com>.
Hi again,

I forgot to say that I've also tried with this:

In the main class I make the call:
wb2.addToolPack(new GEFAddIn());

public class GEFAddIn  implements UDFFinder{

      private final Map<String, FreeRefFunction> _functionsByName;

      public GEFAddIn() {
          // dummy function that returns NA
          // don't care about the implementation, we are not interested 
in evaluation
          // and this method will never be called
          FreeRefFunction NA = new FreeRefFunction() {
              public ValueEval evaluate(ValueEval[] arg0,
                      OperationEvaluationContext arg1) {
                  return ErrorEval.NA;
              }
          };
          _functionsByName = new HashMap<String, FreeRefFunction>();
          _functionsByName.put("Calculo_VPS", NA);

      }

      public FreeRefFunction findFunction(String name) {
          return _functionsByName.get(name.toUpperCase());
      }

}

But it works the same as the other.

Thanks in advance


El 20/11/2012 18:25, Ruben Garcia escribió:
> Good afternoon,
>
> I'm trying to set a formula set in my ExcelSheet template, which 
> contains a VB function to do some calculations. I followed this 
> example 
> http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java 
> but when I create the ExcelSheet, the Cell where I set the formula 
> doesn't show the value, it shows a "name error". Here is my code:
>
>                 Workbook wb2 = WorkbookFactory.create(fis);
>                 String[] functionNames = {"Calculo_VPS"};
>                  FreeRefFunction[] functionImpls = {new 
> FreeRefFunction() {
>
>                         @Override
>                         public ValueEval evaluate(ValueEval[] arg0,
>                                 OperationEvaluationContext arg1) {
>                              // don't care about the returned result. 
> we are not going to evaluate BDP
>                                return ErrorEval.NA;
>
>                         }
>                      }};
>
>                      UDFFinder udfToolpack = new 
> DefaultUDFFinder(functionNames,
>                      functionImpls);
>
>                      // register the user-defined function in the workbook
>                      wb2.addToolPack(udfToolpack);
>
> row2.createCell(19).setCellFormula(formulaC19);
>                 wb2.setForceFormulaRecalculation(true);
>
> I've also tried with this one:
> row2.createCell(19).setCellType(HSSFCell.CELL_TYPE_FORMULA);
> row2.getCell(19)..setCellFormula(formulaC19);
>
> Could anyone help me with this?
> --
>

-- 


Re: Setting a defined user formula Error

Posted by Ruben Garcia <ru...@asi-soluciones.com>.
Is HSSF and Calculo_VPS is defined in the template. It is a VB function.
El 21/11/2012 15:27, Yegor Kozlov escribió:
> HSSF or XSSF ?
> Is Calculo_VPS defined in the template ?
>
> On Tue, Nov 20, 2012 at 9:25 PM, Ruben Garcia <
> ruben.garcia@asi-soluciones.com> wrote:
>
>> Calculo_VPS

-- 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Setting a defined user formula Error

Posted by Yegor Kozlov <ye...@dinom.ru>.
HSSF or XSSF ?
Is Calculo_VPS defined in the template ?

On Tue, Nov 20, 2012 at 9:25 PM, Ruben Garcia <
ruben.garcia@asi-soluciones.com> wrote:

> Calculo_VPS