From 48c0213a205d2ca8a105044cc08692a9ce074756 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 23 Jul 2014 19:09:25 +0000 Subject: [PATCH] Further XSSF external name evaluation lookup support git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1612925 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFEvaluationWorkbook.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 d9d53f7ce4..d9486e3bc2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java @@ -110,7 +110,9 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E for (int i = 0; i < _uBook.getNumberOfNames(); i++) { XSSFName nm = _uBook.getNameAt(i); String nameText = nm.getNameName(); - if (name.equalsIgnoreCase(nameText) && nm.getSheetIndex() == sheetIndex) { + int nameSheetindex = nm.getSheetIndex(); + if (name.equalsIgnoreCase(nameText) && + (nameSheetindex == -1 || nameSheetindex == sheetIndex)) { return new Name(_uBook.getNameAt(i), i, this); } } @@ -138,10 +140,14 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E for (org.apache.poi.ss.usermodel.Name name : linkTable.getDefinedNames()) { if (name.getNameName().equals(nameName)) { + // HSSF returns one sheet higher than normal, and various bits + // of the code assume that. So, make us match that behaviour! + int nameSheetIndex = name.getSheetIndex() + 1; + // TODO Return a more specialised form of this, see bug #56752 // Should include the cached values, for in case that book isn't available // Should support XSSF stuff lookups - return new ExternalName(nameName, -1, name.getSheetIndex()); + return new ExternalName(nameName, -1, nameSheetIndex); } } throw new IllegalArgumentException("Name '"+nameName+"' not found in " + -- 2.39.5