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
This commit is contained in:
Nick Burch 2011-10-05 21:18:25 +00:00
parent ea20b0b885
commit 0d31a3b8b7
4 changed files with 32 additions and 5 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta5" date="2011-??-??">
<action dev="poi-developers" type="fix">51963 - Correct AreaReference handling of references containing a sheet name which includes a comma</action>
<action dev="poi-developers" type="fix">51955 - XSSFReader supplied StylesTables need to have the theme data available</action>
<action dev="poi-developers" type="fix">51716 - Removed incorrect assert in SXSSFSheet#getSXSSFSheet</action>
<action dev="poi-developers" type="fix">51834 - Opening and Writing .doc file results in corrupt document</action>

View File

@ -152,9 +152,16 @@ 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 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;
}

View File

@ -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());
}
}

Binary file not shown.