2

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.

2 Answers2

5

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

Bassem Reda Zohdy
  • 12,662
  • 3
  • 33
  • 39
-1
/**
 * 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

dantuch
  • 9,123
  • 6
  • 45
  • 68
  • This isn't really what question is about. It appears asker is asking about why the EmptyStackException is thrown on a cell addition. – David B Aug 19 '12 at 23:05
  • @David B, but it could be a hint :) – dantuch Aug 19 '12 at 23:15
  • The tutorial helped. As opposed to other tutorials on jexcel I found, this one indicated that formulae should not be entered with the equals sign at the front of the string, which evidently caused parsing errors. As this was common to all of my formulae, none of them had worked until now. – user1610584 Aug 19 '12 at 23:35
  • @user1610584 Glad to hear that. If i helped you, you could accept my answer. Even if it has score below 0 :D – dantuch Aug 19 '12 at 23:43