aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-12-05 00:52:39 +0000
committerNick Burch <nick@apache.org>2011-12-05 00:52:39 +0000
commit36f27c7385b67da5f1261c952982d8d09999068f (patch)
treef0ce9396f91130432538ca0e52de8f88397af005 /src
parent99bd60879af990d6962f36fff29902078be8a11a (diff)
downloadpoi-36f27c7385b67da5f1261c952982d8d09999068f.tar.gz
poi-36f27c7385b67da5f1261c952982d8d09999068f.zip
Patch from Marcel May from bug #51875 - More XSSF formula new-line support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1210299 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/ss/formula/FormulaParser.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java18
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java8
4 files changed, 13 insertions, 20 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index ffee4df0d6..6db3227e44 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -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>
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java
index f9f3ca0c77..3e2f07cc49 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -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 */
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
index e5bec593ba..e9ba3c7bb1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
@@ -34,8 +34,6 @@ import org.apache.poi.ss.formula.udf.UDFFinder;
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 XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
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 {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index 4467dc46a4..d163221d52 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -623,7 +623,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/**
* 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 BaseTestBugzillaIssues {
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());
}
/**