git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1210299 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_8_BETA5
<changes> | <changes> | ||||
<release version="3.8-beta5" date="2011-??-??"> | <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 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="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> | <action dev="poi-developers" type="fix">52209 - fixed inserting multiple pictures in XSLF </action> |
private ParseNode _rootNode; | 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. | * Lookahead Character. | ||||
/** Recognize White Space */ | /** Recognize White Space */ | ||||
private static boolean IsWhite( char c) { | private static boolean IsWhite( char c) { | ||||
return c ==' ' || c== TAB; | |||||
return c ==' ' || c== TAB || c == CR || c == LF; | |||||
} | } | ||||
/** Skip Over Leading White Space */ | /** Skip Over Leading White Space */ |
import org.apache.poi.xssf.model.IndexedUDFFinder; | import org.apache.poi.xssf.model.IndexedUDFFinder; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName; | ||||
import java.util.HashMap; | |||||
/** | /** | ||||
* Internal POI use only | * Internal POI use only | ||||
* | * | ||||
public Ptg[] getFormulaTokens(EvaluationCell evalCell) { | public Ptg[] getFormulaTokens(EvaluationCell evalCell) { | ||||
XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell(); | XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell(); | ||||
XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook); | 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(){ | public UDFFinder getUDFFinder(){ | ||||
return _uBook.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 { | private static final class Name implements EvaluationName { | ||||
/** | /** | ||||
* Newlines are valid characters in a formula | * Newlines are valid characters in a formula | ||||
*/ | */ | ||||
public void test50440() throws Exception { | |||||
public void test50440And51875() throws Exception { | |||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx"); | Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx"); | ||||
Sheet s = wb.getSheetAt(0); | Sheet s = wb.getSheetAt(0); | ||||
Cell c = s.getRow(0).getCell(0); | Cell c = s.getRow(0).getCell(0); | ||||
assertEquals("SUM(\n1,2\n)", c.getCellFormula()); | assertEquals("SUM(\n1,2\n)", c.getCellFormula()); | ||||
assertEquals(3.0, c.getNumericCellValue()); | 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()); | |||||
} | } | ||||
/** | /** |