我是jexcel api的新手,尚未成功添加公式。

每当我尝试编译公式时,都会出现编译错误:

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)


从addCell被调用

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


如果我犯了一些明显的错误,请告诉我,可以采取哪些步骤才能正确地将公式添加到电子表格中。

最佳答案

/**
 * 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);
}


因此您得到的错误类似于NullPointerException,不同之处在于您的堆栈为空,因此您无法从中窥视任何内容。

这可能表明您的string有问题

这是教程http://www.java-tips.org/other-api-tips/jexcel/how-to-create-an-excel-file.html,还讨论了如何创建公式。

这是另一个:http://r4r.co.in/java/apis/jexcel/basic/example/jexcel_basic_examples.php?id=774&option=Jexcel%20Example

07-26 08:46