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/07/26 17:52:57 UTC

svn commit: r979329 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/formula/FormulaParser.java testcases/org/apache/poi/hssf/usermodel/TestFormulas.java

Author: yegor
Date: Mon Jul 26 15:52:57 2010
New Revision: 979329

URL: http://svn.apache.org/viewvc?rev=979329&view=rev
Log:
 Fixed parsing formulas containing defined names beginning with an underscore, see Bug 9640

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/usermodel/TestFormulas.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=979329&r1=979328&r2=979329&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Jul 26 15:52:57 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="add">49640 - Fixed parsing formulas containing defined names beginning with an underscore</action>
            <action dev="POI-DEVELOPERS" type="add">49538 - Added implementation for POISSON()</action>
            <action dev="POI-DEVELOPERS" type="add">49524 - Support for setting cell text to be vertically rotated, via style.setRotation(0xff)</action>
            <action dev="POI-DEVELOPERS" type="fix">49609 - Case insensitive matching of OOXML part names</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=979329&r1=979328&r2=979329&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 Mon Jul 26 15:52:57 2010
@@ -52,6 +52,7 @@ import org.apache.poi.ss.util.CellRefere
  *  @author Peter M. Murray (pete at quantrix dot com)
  *  @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
  *  @author Josh Micich
+ *  @author David Lewis (DLewis400 at gmail dot com)
  */
 public final class FormulaParser {
 	private static final class Identifier {
@@ -537,7 +538,8 @@ public final class FormulaParser {
 		// which will either be named ranges or functions
 		StringBuilder sb = new StringBuilder();
 
-		if (!Character.isLetter(look)) {
+		// defined names may begin with a letter or underscore
+		if (!Character.isLetter(look) && look != '_') {
 			throw expected("number, string, or defined name");
 		}
 		while (isValidDefinedNameChar(look)) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java?rev=979329&r1=979328&r2=979329&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java Mon Jul 26 15:52:57 2010
@@ -31,6 +31,9 @@ import org.apache.poi.hssf.record.formul
 import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.ss.formula.FormulaType;
+import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Cell;
 
 /**
  * @author Andrew C. Oliver (acoliver at apache dot org)
@@ -935,4 +938,24 @@ public final class TestFormulas extends 
         assertEquals(5.0, evaluator.evaluate(sh2.getRow(0).getCell(1)).getNumberValue(), 0.0);
         assertEquals(15.0, evaluator.evaluate(sh2.getRow(0).getCell(2)).getNumberValue(), 0.0);
     }
+
+    /**
+     * Verify that FormulaParser handles defined names beginning with underscores,
+     * see Bug #49640
+     */
+    public void testFormulasWithUnderscore(){
+        HSSFWorkbook wb = new HSSFWorkbook();
+        Name nm1 = wb.createName();
+        nm1.setNameName("_score1");
+        nm1.setRefersToFormula("A1");
+
+        Name nm2 = wb.createName();
+        nm2.setNameName("_score2");
+        nm2.setRefersToFormula("A2");
+
+        Sheet sheet = wb.createSheet();
+        Cell cell = sheet.createRow(0).createCell(2);
+        cell.setCellFormula("_score1*SUM(_score1+_score2)");
+        assertEquals("_score1*SUM(_score1+_score2)", cell.getCellFormula());
+    }
 }



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