From: Yegor Kozlov Date: Sun, 15 Feb 2009 20:45:24 +0000 (+0000) Subject: Fixed formula parser to handle names with backslashes X-Git-Tag: REL_3_5_BETA6~119 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bab3dc4265f2116ef54cb4b06cc804d9b9c2db2;p=poi.git Fixed formula parser to handle names with backslashes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@744749 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 8728066237..c59adc2e72 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + Fixed formula parser to handle names with backslashes 46660 - added Workbook getHidden() and setHidden(boolean) 46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX 46627 - Fixed offset of added images if Pictures stream contains pictures with zero length diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 791ff90291..386c5f998f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Fixed formula parser to handle names with backslashes 46660 - added Workbook getHidden() and setHidden(boolean) 46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX 46627 - Fixed offset of added images if Pictures stream contains pictures with zero length diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java index e67e6b3023..98c93e0e5c 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java @@ -298,7 +298,7 @@ public final class FormulaParser { } else { // allow for any sequence of dots and identifier chars // special case of two consecutive dots is best treated in the calling code - while (IsAlNum(look) || look == '.' || look == '[' || look == ']') { + while (IsAlNum(look) || look == '.' || look == '[' || look == ']' || look == '\\') { sb.append(look); GetChar(); } diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index a6ff9fd519..21edfa37e2 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -996,4 +996,25 @@ public final class TestFormulaParser extends TestCase { MemFuncPtg mf = (MemFuncPtg)ptgs[0]; assertEquals(15, mf.getLenRefSubexpression()); } + + /** Named ranges with backslashes, e.g. 'POI\\2009' */ + public void testBackSlashInNames() { + HSSFWorkbook wb = new HSSFWorkbook(); + + HSSFName name = wb.createName(); + name.setNameName("POI\\2009"); + name.setRefersToFormula("Sheet1!$A$1"); + + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + + HSSFCell cell_C1 = row.createCell(2); + cell_C1.setCellFormula("POI\\2009"); + assertEquals("POI\\2009", cell_C1.getCellFormula()); + + HSSFCell cell_D1 = row.createCell(2); + cell_D1.setCellFormula("NOT(POI\\2009=\"3.5-final\")"); + assertEquals("NOT(POI\\2009=\"3.5-final\")", cell_D1.getCellFormula()); + } + }