mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
99bd60879a
commit
36f27c7385
|
@ -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>
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue