import org.apache.poi.ss.formula.ptg.MissingArgPtg;
import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.NameXPtg;
+import org.apache.poi.ss.formula.ptg.NameXPxg;
import org.apache.poi.ss.formula.ptg.NumberPtg;
import org.apache.poi.ss.formula.ptg.OperationPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
return eval;
}
}
+ if (ptg instanceof NameXPxg) {
+ // TODO This is a temporary hack....
+ NameXPxg pxg = (NameXPxg)ptg;
+ int sIdx = -1;
+ if (pxg.getSheetName() != null) {
+ sIdx = _workbook.getSheetIndex(pxg.getSheetName());
+ }
+ EvaluationName evalName = _workbook.getName(pxg.getNameName(), sIdx);
+ if (evalName == null) {
+ // We don't know about that name, sorry
+ // TODO What about UDFs?
+ logInfo("Unknown Name referenced: " + pxg.getNameName());
+ return ErrorEval.NAME_INVALID;
+ }
+
+ int nIdx = evalName.createPtg().getIndex();
+ NameXPtg nptg = new NameXPtg(sIdx, nIdx);
+ return getEvalForPtg(nptg, ec);
+ }
if (ptg instanceof IntPtg) {
return new NumberEval(((IntPtg)ptg).getValue());
import org.apache.poi.ss.formula.ptg.NameXPtg;
/**
- * @author Josh Micich
+ * Evaluation of a Name defined in a Sheet or Workbook scope
*/
public final class NameXEval implements ValueEval {
-
private final NameXPtg _ptg;
public NameXEval(NameXPtg ptg) {
public void bug48539() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48539.xlsx");
assertEquals(3, wb.getNumberOfSheets());
+ assertEquals(0, wb.getNumberOfNames());
// Try each cell individually
XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
for(Row r : s) {
for(Cell c : r) {
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
- CellValue cv = eval.evaluate(c);
+ String formula = c.getCellFormula();
+ CellValue cv;
+ try {
+ cv = eval.evaluate(c);
+ } catch (Exception e) {
+ throw new RuntimeException("Can't evaluate formula: " + formula, e);
+ }
+
if(cv.getCellType() == Cell.CELL_TYPE_NUMERIC) {
// assert that the calculated value agrees with
// the cached formula result calculated by Excel
* org.apache.poi.ss.formula.FormulaParseException: Parse error near char 0 '[' in specified formula '[0]!NR_Global_B2'. Expected number, string, or defined name
*/
@Test
- @Ignore
+ @Ignore("Bug 56737 remains outstanding to fix")
public void bug56737() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");