View | Details | Raw Unified | Return to bug 51875
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/formula/FormulaParser.java (-2 / +2 lines)
Lines 121-127 Link Here
121
121
122
	private ParseNode _rootNode;
122
	private ParseNode _rootNode;
123
123
124
	private static char TAB = '\t';
124
	private final static char TAB = '\t';
125
125
126
	/**
126
	/**
127
	 * Lookahead Character.
127
	 * Lookahead Character.
Lines 229-235 Link Here
229
229
230
	/** Recognize White Space */
230
	/** Recognize White Space */
231
	private static boolean IsWhite( char c) {
231
	private static boolean IsWhite( char c) {
232
		return  c ==' ' || c== TAB;
232
		return  c ==' ' || c== TAB || c == '\r' || c == '\n';
233
	}
233
	}
234
234
235
	/** Skip Over Leading White Space */
235
	/** Skip Over Leading White Space */
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (-17 / +1 lines)
Lines 34-41 Link Here
34
import org.apache.poi.xssf.model.IndexedUDFFinder;
34
import org.apache.poi.xssf.model.IndexedUDFFinder;
35
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
35
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
36
36
37
import java.util.HashMap;
38
39
/**
37
/**
40
 * Internal POI use only
38
 * Internal POI use only
41
 *
39
 *
Lines 147-172 Link Here
147
	public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
145
	public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
148
		XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
146
		XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
149
		XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook);
147
		XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook);
150
		String formulaText = cleanXSSFFormulaText(cell.getCellFormula());
148
		return FormulaParser.parse(cell.getCellFormula(), frBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
151
		return FormulaParser.parse(formulaText, frBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
152
	}
149
	}
153
150
154
    public UDFFinder getUDFFinder(){
151
    public UDFFinder getUDFFinder(){
155
        return _uBook.getUDFFinder();
152
        return _uBook.getUDFFinder();
156
    }
153
    }
157
    
158
   /**
159
    * XSSF allows certain extra textual characters in the formula that
160
    *  HSSF does not. As these can't be composed down to HSSF-compatible
161
    *  Ptgs, this method strips them out for us.
162
    */
163
   private String cleanXSSFFormulaText(String text) {
164
      // Newlines are allowed in XSSF
165
      text = text.replaceAll("\\n", "").replaceAll("\\r", "");
166
      
167
      // All done with cleaning
168
      return text;
169
   }
170
154
171
	private static final class Name implements EvaluationName {
155
	private static final class Name implements EvaluationName {
172
156
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (-2 / +8 lines)
Lines 622-628 Link Here
622
    /**
622
    /**
623
     * Newlines are valid characters in a formula
623
     * Newlines are valid characters in a formula
624
     */
624
     */
625
    public void test50440() throws Exception {
625
    public void test50440And51875() throws Exception {
626
       Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx");
626
       Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx");
627
       Sheet s = wb.getSheetAt(0);
627
       Sheet s = wb.getSheetAt(0);
628
       Cell c = s.getRow(0).getCell(0);
628
       Cell c = s.getRow(0).getCell(0);
Lines 631-640 Link Here
631
       assertEquals(3.0, c.getNumericCellValue());
631
       assertEquals(3.0, c.getNumericCellValue());
632
       
632
       
633
       FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
633
       FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
634
       formulaEvaluator.evaluateFormulaCell(c);
634
       formulaEvaluator.evaluateFormulaCell(c);
635
       
635
       
636
       assertEquals("SUM(\n1,2\n)", c.getCellFormula());
636
       assertEquals("SUM(\n1,2\n)", c.getCellFormula());
637
       assertEquals(3.0, c.getNumericCellValue());
637
       assertEquals(3.0, c.getNumericCellValue());
638
639
       // For 51875
640
       Cell b3 = s.getRow(2).getCell(1);
641
       formulaEvaluator.evaluateFormulaCell(b3);
642
       assertEquals("B1+B2", b3.getCellFormula()); // The newline is lost for shared formulas
643
       assertEquals(3.0, b3.getNumericCellValue());
638
    }
644
    }
639
    
645
    
640
    /**
646
    /**

Return to bug 51875