You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/12/05 01:52:39 UTC

svn commit: r1210299 - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/ss/formula/ src/ooxml/java/org/apache/poi/xssf/usermodel/ src/ooxml/testcases/org/apache/poi/xssf/usermodel/ test-data/spreadsheet/

Author: nick
Date: Mon Dec  5 00:52:39 2011
New Revision: 1210299

URL: http://svn.apache.org/viewvc?rev=1210299&view=rev
Log:
Patch from Marcel May from bug #51875 - More XSSF formula new-line support

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/test-data/spreadsheet/NewlineInFormulas.xlsx

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1210299&r1=1210298&r2=1210299&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Dec  5 00:52:39 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51875 - More XSSF new-line in formula support</action>
            <action dev="poi-developers" type="add">POIFS EntryUtils.copyNodes(POFS,POIFS) now uses FilteringDirectoryNode, so can exclude from copying nodes not just directly under the root</action>
            <action dev="poi-developers" type="add">POIFS Helper FilteringDirectoryNode, which wraps a DirectoryEntry and allows certain parts to be ignored</action>
            <action dev="poi-developers" type="fix">52209 - fixed inserting multiple pictures in XSLF </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=1210299&r1=1210298&r2=1210299&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 Dec  5 00:52:39 2011
@@ -121,7 +121,9 @@ public final class FormulaParser {
 
 	private ParseNode _rootNode;
 
-	private static char TAB = '\t';
+	private final static char TAB = '\t'; // HSSF + XSSF
+	private final static char CR = '\r';  // Normally just XSSF
+	private final static char LF = '\n';  // Normally just XSSF
 
 	/**
 	 * Lookahead Character.
@@ -229,7 +231,7 @@ public final class FormulaParser {
 
 	/** Recognize White Space */
 	private static boolean IsWhite( char c) {
-		return  c ==' ' || c== TAB;
+		return  c ==' ' || c== TAB || c == CR || c == LF;
 	}
 
 	/** Skip Over Leading White Space */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java?rev=1210299&r1=1210298&r2=1210299&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java Mon Dec  5 00:52:39 2011
@@ -34,8 +34,6 @@ import org.apache.poi.ss.formula.udf.UDF
 import org.apache.poi.xssf.model.IndexedUDFFinder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
 
-import java.util.HashMap;
-
 /**
  * Internal POI use only
  *
@@ -147,26 +145,12 @@ public final class XSSFEvaluationWorkboo
 	public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
 		XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
 		XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook);
-		String formulaText = cleanXSSFFormulaText(cell.getCellFormula());
-		return FormulaParser.parse(formulaText, frBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
+		return FormulaParser.parse(cell.getCellFormula(), frBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
 	}
 
     public UDFFinder getUDFFinder(){
         return _uBook.getUDFFinder();
     }
-    
-   /**
-    * XSSF allows certain extra textual characters in the formula that
-    *  HSSF does not. As these can't be composed down to HSSF-compatible
-    *  Ptgs, this method strips them out for us.
-    */
-   private String cleanXSSFFormulaText(String text) {
-      // Newlines are allowed in XSSF
-      text = text.replaceAll("\\n", "").replaceAll("\\r", "");
-      
-      // All done with cleaning
-      return text;
-   }
 
 	private static final class Name implements EvaluationName {
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1210299&r1=1210298&r2=1210299&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Mon Dec  5 00:52:39 2011
@@ -623,7 +623,7 @@ public final class TestXSSFBugs extends 
     /**
      * Newlines are valid characters in a formula
      */
-    public void test50440() throws Exception {
+    public void test50440And51875() throws Exception {
        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx");
        Sheet s = wb.getSheetAt(0);
        Cell c = s.getRow(0).getCell(0);
@@ -636,6 +636,12 @@ public final class TestXSSFBugs extends 
        
        assertEquals("SUM(\n1,2\n)", c.getCellFormula());
        assertEquals(3.0, c.getNumericCellValue());
+
+       // For 51875
+       Cell b3 = s.getRow(2).getCell(1);
+       formulaEvaluator.evaluateFormulaCell(b3);
+       assertEquals("B1+B2", b3.getCellFormula()); // The newline is lost for shared formulas
+       assertEquals(3.0, b3.getNumericCellValue());
     }
     
     /**

Modified: poi/trunk/test-data/spreadsheet/NewlineInFormulas.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/NewlineInFormulas.xlsx?rev=1210299&r1=1210298&r2=1210299&view=diff
==============================================================================
Binary files - no diff available.



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