-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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.
@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.
Asked: 2011-03-02 10:56:22 +0800
Seen: 598 times
Last updated: Mar 21 '11