0

java.lang.IllegalArgumentException: ptgs must not be null

asked 2011-03-02 10:56:22 +0800

dmoralesnava gravatar image dmoralesnava
42

Hi.

I'm trying to insert a calculation formula from java to my ZK SpreadSheet, but im getting de error:

2/03/2011 10:50:05 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1253
GRAVE: >>java.lang.IllegalArgumentException: ptgs must not be null
>> at org.zkoss.poi.ss.formula.FormulaRenderer.toFormulaString(FormulaRenderer.java:48)
>> at org.zkoss.poi.hssf.model.HSSFFormulaParser.toFormulaString(HSSFFormulaParser.java:83)
>> at org.zkoss.poi.hssf.usermodel.HSSFCell.getCellFormula(HSSFCell.java:633)
>> at org.zkoss.zss.model.impl.BookHelper.getCellValue(BookHelper.java:881)
>> at org.zkoss.zss.model.impl.BookHelper.sameTypeAndValue(BookHelper.java:1034)
>> at org.zkoss.zss.model.impl.BookHelper.setCellFormula(BookHelper.java:981)
>>...


The way I'm setting that calculation formula is by calling a method called insertaFormula, which has the next code:

private void insertaFormulas(Worksheet ws1) {
Double dolar = 13.0;
Double IVA = 1.16;
for (int i = 1; i < 26; i++) {
//String expr = "=B"+(i+1)+"*"+dolar+"*"+IVA;
String expr = "=B2";
System.out.println(expr);
Ranges.range(ws1, i, 2).setValue(expr);
//Ranges.range(workSheet1, i+1, 1).setValue("=B2");
}
}

The only thing I wanna do in this example is to make a reference to other cell in my SpreadSheet by a formula.

Thanks.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-03-09 00:36:09 +0800

PeterKuo gravatar image PeterKuo
481 2

It's a bug, I reported in
http://code.google.com/p/zkspreadsheet/issues/detail?id=296

link publish delete flag offensive edit

answered 2011-03-09 10:12:30 +0800

dmoralesnava gravatar image dmoralesnava
42

Hi PeterKuo.

I already find the solution. The way I was trying to set a formula value was wrong, the right way is using a Cell object with its method setCellFormula(formula). This is how mi code finally worked:

private void insertaFormulas(Worksheet ws1) {
//Cell cell;
Double dolar = 13.0;
Double IVA = 1.16;
//Row row;
Cell cell;
String expr;
Ranges.range(ws1, 1, 1).setHidden(true);
for (int i = 1; i < 26; i++) {
Ranges.range(ws1, i, 2).setValue(1);
//row = ws1.getRow(i);
//cell = row.getCell(2);
cell = Utils.getCell(ws1, i, 2);
expr = "B"+(i+1)+"*"+dolar+"*"+IVA;
cell.setCellFormula(expr);
//evaluator.evaluateFormulaCell(cell);
}
}

As you see, with Utils.getCell(ws1, i, 2); I get the specific cell i want to evaluate or in which i wanna set a formula value, so to set a formula you only have to use setCellFormula and thats all!

The only doubt I have is that when a cell I wanna get is null (have no value) I can't manipulate my Cell object, so what I'm doing here is setting a value to every cell i'm getting, this way i can insert the formula.

link publish delete flag offensive edit

answered 2011-03-21 23:40:19 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

@dmoralesnava,

The bug is fixed today.

Calling setCellFormula directly is not suggested. It by-pass ZK Spreadsheet code so the UI DOES NOT know that the back-end Book model has been changed and will not reflect itself. However, if you simply want to change the back-end book model but don't care about UI reflection, then it is OK.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-02 10:56:22 +0800

Seen: 598 times

Last updated: Mar 21 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More