user1610584
user1610584

Reputation: 23

EmptyStackException for Formula parsing in jexcel

I am new to the jexcel api and have not yet successfully added a formula.

Whenever I try to compile a formula I get the compile error:

Exception in thread "main" java.util.EmptyStackException
     at java.util.Stack.peek(Stack.java:102)
     at java.util.Stack.pop(Stack.java:84)
     at jxl.biff.formula.BinaryOperator.getOperands(BinaryOperator.java:61)
     at jxl.biff.formula.StringFormulaParser.parseCurrent(StringFormulaParser.java:240)
     at jxl.biff.formula.StringFormulaParser.parse(StringFormulaParser.java:113)
     at jxl.biff.formula.FormulaParser.parse(FormulaParser.java:161)
     at jxl.write.biff.FormulaRecord.initialize(FormulaRecord.java:160)
     at jxl.write.biff.FormulaRecord.setCellDetails(FormulaRecord.java:243)
     at jxl.write.biff.WritableSheetImpl.addCell(WritableSheetImpl.java:1199)

With addCell being called from

Formula formula;
formula = new Formula(column, row, string, arial);
sheet.addCell(formula);

Please let me know if I'm making some obvious mistake and what steps I can take in order to properly add a formula to my spreadsheet.

Upvotes: 2

Views: 1403

Answers (2)

Bassem Reda Zohdy
Bassem Reda Zohdy

Reputation: 12942

I faced the same issue and my problem was that I was putting "=" before the expression, just removed it and it is working with no error

Upvotes: 5

dantuch
dantuch

Reputation: 9293

/**
 * Looks at the object at the top of this stack without removing it
 * from the stack.
 *
 * @return     the object at the top of this stack (the last item
 *             of the <tt>Vector</tt> object).
 * @exception  EmptyStackException  if this stack is empty.
 */
public synchronized E peek() {
int len = size();

if (len == 0)
    throw new EmptyStackException();
return elementAt(len - 1);
}

so the error you got is similar to NullPointerException, with the difference, that your stack is empty, so you can't peek anything from it.

That can suggest that there's something wrong with your string

Here is a tutorial http://www.java-tips.org/other-api-tips/jexcel/how-to-create-an-excel-file.html talking also about creating Formulas.

And here is anouther one: http://r4r.co.in/java/apis/jexcel/basic/example/jexcel_basic_examples.php?id=774&option=Jexcel%20Example

Upvotes: -1

Related Questions