Better reporting on why a test is failing, and partial NameXPxg eval

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-07-19 21:27:28 +00:00
parent 81869b869d
commit 0b1dee9913
3 changed files with 31 additions and 4 deletions

View File

@ -62,6 +62,7 @@ import org.apache.poi.ss.formula.ptg.MemFuncPtg;
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;
@ -650,6 +651,25 @@ public final class WorkbookEvaluator {
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());

View File

@ -20,10 +20,9 @@ package org.apache.poi.ss.formula.eval;
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) {

View File

@ -266,6 +266,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
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);
@ -274,7 +275,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
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
@ -1661,7 +1669,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* 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");