aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-07-18 22:50:54 +0000
committerNick Burch <nick@apache.org>2014-07-18 22:50:54 +0000
commitde3ba9dc6a83123b4d8d28a4cedf07e009423592 (patch)
tree5f828b764dc24b8f2a4dce77a88f35aae8a69e47
parent2643dfdef447d25119bd9cc54b0e27600054bd0a (diff)
downloadpoi-de3ba9dc6a83123b4d8d28a4cedf07e009423592.tar.gz
poi-de3ba9dc6a83123b4d8d28a4cedf07e009423592.zip
Bit more towards XSSF name support for #56737, will need some deeper changes though to fully implement
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611830 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java29
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java5
-rw-r--r--test-data/spreadsheet/ref-56737.xlsxbin0 -> 10427 bytes
3 files changed, 26 insertions, 8 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
index 660f2dc40c..ea9f93d619 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
@@ -103,16 +103,39 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
}
public NameXPtg getNameXPtg(String name, int sheetRefIndex) {
+ // First, try to find it as a User Defined Function
IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
FreeRefFunction func = udfFinder.findFunction(name);
- if(func == null) return null;
- else return new NameXPtg(0, udfFinder.getFunctionIndex(name));
+ if (func != null) {
+ return new NameXPtg(0, udfFinder.getFunctionIndex(name));
+ }
+
+ // Otherwise, try it as a named range
+ XSSFName xname = _uBook.getName(name);
+ if (xname != null) {
+ int nameAt = _uBook.getNameIndex(name);
+ return new NameXPtg(xname.getSheetIndex(), nameAt);
+ } else {
+ return null;
+ }
}
public String resolveNameXText(NameXPtg n) {
int idx = n.getNameIndex();
+ String name = null;
+
+ // First, try to find it as a User Defined Function
IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
- return udfFinder.getFunctionName(idx);
+ name = udfFinder.getFunctionName(idx);
+ if (name != null) return name;
+
+ // Otherwise, try it as a named range
+ XSSFName xname = _uBook.getNameAt(idx);
+ if (xname != null) {
+ name = xname.getNameName();
+ }
+
+ return name;
}
public EvaluationSheet getSheet(int sheetIndex) {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index ad6f693ab2..9421b56348 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -2678,10 +2678,5 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Try to evaluate everything
eval.evaluateAll();
-
- // Try to set the same kinds of formula elsewhere
- Cell newF = s.getRow(0).createCell(10, Cell.CELL_TYPE_FORMULA);
- // TODO Fix this
- //newF.setCellFormula("Defines!NR_To_A1");
}
}
diff --git a/test-data/spreadsheet/ref-56737.xlsx b/test-data/spreadsheet/ref-56737.xlsx
new file mode 100644
index 0000000000..3703827391
--- /dev/null
+++ b/test-data/spreadsheet/ref-56737.xlsx
Binary files differ