From a45b2cd33f452068b542cf423812f7377d000e82 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 5 Oct 2011 21:18:25 +0000 Subject: [PATCH] Fix bug #51963 - Correct AreaReference handling of references containing a sheet name which includes a comma git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1179444 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/ss/util/AreaReference.java | 17 +++++++++++----- .../poi/xssf/usermodel/TestXSSFBugs.java | 19 ++++++++++++++++++ test-data/spreadsheet/51963.xlsx | Bin 0 -> 7138 bytes 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test-data/spreadsheet/51963.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 219eb30932..cb49fb56ab 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51963 - Correct AreaReference handling of references containing a sheet name which includes a comma 51955 - XSSFReader supplied StylesTables need to have the theme data available 51716 - Removed incorrect assert in SXSSFSheet#getSXSSFSheet 51834 - Opening and Writing .doc file results in corrupt document diff --git a/src/java/org/apache/poi/ss/util/AreaReference.java b/src/java/org/apache/poi/ss/util/AreaReference.java index ffa0c8888d..2082634d18 100644 --- a/src/java/org/apache/poi/ss/util/AreaReference.java +++ b/src/java/org/apache/poi/ss/util/AreaReference.java @@ -152,13 +152,20 @@ public class AreaReference { * unbroken) area, or is it made up of * several different parts? * (If it is, you will need to call - * .... + * {@link #generateContiguous(String)}) */ public static boolean isContiguous(String reference) { - if(reference.indexOf(',') == -1) { - return true; - } - return false; + // If there's a sheet name, strip it off + int sheetRefEnd = reference.indexOf('!'); + if(sheetRefEnd != -1) { + reference = reference.substring(sheetRefEnd); + } + + // Check for the , as a sign of non-coniguous + if(reference.indexOf(',') == -1) { + return true; + } + return false; } public static AreaReference getWholeRow(String start, String end) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index dd62f7d668..4467dc46a4 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -43,6 +43,7 @@ import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.AreaReference; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.CalculationChain; @@ -1230,4 +1231,22 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertNotNull(sh1.getCommentsTable(false)); assertEquals(2, sh1.getCommentsTable(false).getNumberOfComments()); } + + /** + * Sheet names with a , in them + */ + public void test51963() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51963.xlsx"); + XSSFSheet sheet = wb.getSheetAt(0); + assertEquals("Abc,1", sheet.getSheetName()); + + Name name = wb.getName("Intekon.ProdCodes"); + assertEquals("'Abc,1'!$A$1:$A$2", name.getRefersToFormula()); + + AreaReference ref = new AreaReference(name.getRefersToFormula()); + assertEquals(0, ref.getFirstCell().getRow()); + assertEquals(0, ref.getFirstCell().getCol()); + assertEquals(1, ref.getLastCell().getRow()); + assertEquals(0, ref.getLastCell().getCol()); + } } diff --git a/test-data/spreadsheet/51963.xlsx b/test-data/spreadsheet/51963.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..154c75418a717cc8b5d2556543ef2dd045b7aa70 GIT binary patch literal 7138 zcmeHMhgVZ;_6;B0Nq9x-=0aR1xW&2qIFY zBOpyP@y*Q7_Za6NnBTiu>wYUMcb|1v_CDV^XMZ~CSl1{3H~>5V0Kg1*AF!6Mg#iHI zT>}8f0Ut4p6(LS;)=q9_54@q)t|kIrj$oz&BnDR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