You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2010/08/12 17:10:12 UTC

svn commit: r984823 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/formula/FormulaParser.java testcases/org/apache/poi/hssf/model/TestFormulaParser.java

Author: yegor
Date: Thu Aug 12 15:10:12 2010
New Revision: 984823

URL: http://svn.apache.org/viewvc?rev=984823&view=rev
Log:
 fixed FormulaParser to correctly process defined names with underscore, see bugzilla 49725

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
    poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=984823&r1=984822&r2=984823&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Aug 12 15:10:12 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49725 - fixed FormulaParser to correctly process defined names with underscore</action>
            <action dev="POI-DEVELOPERS" type="add">48526 - added implementation for RANDBETWEEN()</action>
            <action dev="POI-DEVELOPERS" type="fix">49725 - avoid exception in OperandResolver.parseDouble when input is minus ("-")</action>
            <action dev="POI-DEVELOPERS" type="fix">49723 - fixed OperandResolver to correctly handle inputs with leading decimal place</action>

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java?rev=984823&r1=984822&r2=984823&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java Thu Aug 12 15:10:12 2010
@@ -665,7 +665,7 @@ public final class FormulaParser {
 				hasDigits = true;
 			} else if (Character.isLetter(ch)) {
 				hasLetters = true;
-			} else if (ch =='$') {
+			} else if (ch =='$' || ch =='_') {
 				//
 			} else {
 				break;

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=984823&r1=984822&r2=984823&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Thu Aug 12 15:10:12 2010
@@ -271,7 +271,51 @@ public final class TestFormulaParser ext
 		cell.setCellFormula("Cash_Flow!A1");
 	}
 
-	// bug 38396 : Formula with exponential numbers not parsed correctly.
+    /** bug 49725, defined names with underscore */
+    public void testNamesWithUnderscore() {
+        HSSFWorkbook wb = new HSSFWorkbook(); //or new XSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet("NamesWithUnderscore");
+
+        HSSFName nm;
+
+        nm = wb.createName();
+        nm.setNameName("DA6_LEO_WBS_Number");
+        nm.setRefersToFormula("33");
+
+        nm = wb.createName();
+        nm.setNameName("DA6_LEO_WBS_Name");
+        nm.setRefersToFormula("33");
+
+        nm = wb.createName();
+        nm.setNameName("A1_");
+        nm.setRefersToFormula("22");
+
+        nm = wb.createName();
+        nm.setNameName("_A1");
+        nm.setRefersToFormula("11");
+
+        nm = wb.createName();
+        nm.setNameName("A_1");
+        nm.setRefersToFormula("44");
+
+        nm = wb.createName();
+        nm.setNameName("A_1_");
+        nm.setRefersToFormula("44");
+
+        HSSFRow row = sheet.createRow(0);
+        HSSFCell cell = row.createCell(0);
+
+        cell.setCellFormula("DA6_LEO_WBS_Number*2");
+        assertEquals("DA6_LEO_WBS_Number*2", cell.getCellFormula());
+
+        cell.setCellFormula("(A1_*_A1+A_1)/A_1_");
+        assertEquals("(A1_*_A1+A_1)/A_1_", cell.getCellFormula());
+
+        cell.setCellFormula("INDEX(DA6_LEO_WBS_Name,MATCH($A3,DA6_LEO_WBS_Number,0))");
+        assertEquals("INDEX(DA6_LEO_WBS_Name,MATCH($A3,DA6_LEO_WBS_Number,0))", cell.getCellFormula());
+    }
+
+    // bug 38396 : Formula with exponential numbers not parsed correctly.
 	public void testExponentialParsing() {
 		confirmTokenClasses("1.3E21/2",  NumberPtg.class, IntPtg.class, DividePtg.class);
 		confirmTokenClasses("1322E21/2", NumberPtg.class, IntPtg.class, DividePtg.class);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org