Thanks a lot, that was the problem. Sorry for wasting the bandwidth. I
think I should have gotten some fresh air before I asked...
I guess the error saying "Integer expected" sidetracked me. Maybe an
error message like "messed up formula" or something.
Lloyd
Amol Deshmukh wrote:
Ok, if you are using cell references in your formula,
there really should not be any problem. The formula
parser does not evaluate the cell references, so it
does not matter what goes into the cell (as far as
POI is concerned).
Incidentally the code you posted seems to have a
typo:
cell.setCellFormula("SUM(C2:C10");
should really be
cell.setCellFormula("SUM(C2:C10)");
closing paren --^
If that is how it is in the original code, you
may want to correct that :)
HTH,
~ amol
-----Original Message-----
From: Lloyd H. Meinholz [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 17, 2005 11:42 AM
To: POI Users List
Subject: Re: setCellFormula() quest
yes, a little different. my formula is "SUM(D2:D10)". This
seems to work
with int, but not decimals. I tried summing some of the columns that
were int only and the Sum worked, but when a column has
decimal points,
it didn't. Funny thing is, I tried a simple test similar to
what you've
done and it works. I can't figure out what is different.
The line of code that causes the error is:
cell.setCellFormula("SUM(C2:C10");
The error I get is runtime error:
Error: Integer Expected
Exception in thread "main" java.lang.RuntimeException: Cannot Parse,
sorry : Integer Expected
at
org.apache.poi.hssf.model.FormulaParser.Abort(FormulaParser.java:117)
at
org.apache.poi.hssf.model.FormulaParser.Expected(FormulaParser
.java:124)
at
org.apache.poi.hssf.model.FormulaParser.GetNum(FormulaParser.java:239)
at
org.apache.poi.hssf.model.FormulaParser.Factor(FormulaParser.java:479)
at
org.apache.poi.hssf.model.FormulaParser.Term(FormulaParser.java:548)
at
org.apache.poi.hssf.model.FormulaParser.Expression(FormulaPars
er.java:596)
at
org.apache.poi.hssf.model.FormulaParser.Arguments(FormulaParse
r.java:453)
at
org.apache.poi.hssf.model.FormulaParser.function(FormulaParser
.java:315)
at
org.apache.poi.hssf.model.FormulaParser.Ident(FormulaParser.java:265)
at
org.apache.poi.hssf.model.FormulaParser.Factor(FormulaParser.java:474)
at
org.apache.poi.hssf.model.FormulaParser.Term(FormulaParser.java:548)
at
org.apache.poi.hssf.model.FormulaParser.Expression(FormulaPars
er.java:596)
at
org.apache.poi.hssf.model.FormulaParser.parse(FormulaParser.java:700)
at
org.apache.poi.hssf.usermodel.HSSFCell.setCellFormula(HSSFCell
.java:678)
A simplification of my sheet seems to work, so maybe I'm messing up
somewhere. I'm trying to go through it now. Thanks for the help,
Lloyd
Amol Deshmukh wrote:
Lloyd,
The following code works for me:
<code>
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class SimpleTest {
public static void main(String[] args) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCell cell =
workbook.createSheet().createRow(0).createCell((short) 0);
cell.setCellFormula("SUM(1.5,2.3333)");
workbook.write(new FileOutputStream("Simple.xls"));
}
}
</code>
Are you trying something along different lines?
What is the exact nature of the problem you are
facing (exception/unexpected results)?
~ amol
-----Original Message-----
From: Lloyd H. Meinholz [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 17, 2005 9:37 AM
To: [email protected]
Subject: setCellFormula() quest
Is there a way to use setCellFormula() when the cell values
included in
the formula are non integer numeric values (ex. 3.5)?
I seem to be able to get setCellFormula() to work with
int's but not
other numeric types. If not, is it really difficult to add
that support
or should it be relatively easy? Thanks,
Lloyd
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/