mirror of https://github.com/apache/poi.git
Start re-enabling some SXSSF formula evaluation tests, with required fixes #58200
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52877b8368
commit
e4c9b7ca51
|
@ -908,7 +908,9 @@ public class SXSSFCell implements Cell {
|
||||||
}
|
}
|
||||||
private String convertCellValueToString() {
|
private String convertCellValueToString() {
|
||||||
int cellType = getCellType();
|
int cellType = getCellType();
|
||||||
|
return convertCellValueToString(cellType);
|
||||||
|
}
|
||||||
|
private String convertCellValueToString(int cellType) {
|
||||||
switch (cellType) {
|
switch (cellType) {
|
||||||
case CELL_TYPE_BLANK:
|
case CELL_TYPE_BLANK:
|
||||||
return "";
|
return "";
|
||||||
|
@ -922,6 +924,12 @@ public class SXSSFCell implements Cell {
|
||||||
byte errVal = getErrorCellValue();
|
byte errVal = getErrorCellValue();
|
||||||
return FormulaError.forInt(errVal).getString();
|
return FormulaError.forInt(errVal).getString();
|
||||||
case CELL_TYPE_FORMULA:
|
case CELL_TYPE_FORMULA:
|
||||||
|
if (_value != null) {
|
||||||
|
FormulaValue fv = (FormulaValue)_value;
|
||||||
|
if (fv.getFormulaType() != CELL_TYPE_FORMULA) {
|
||||||
|
return convertCellValueToString(fv.getFormulaType());
|
||||||
|
}
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected cell type (" + cellType + ")");
|
throw new IllegalStateException("Unexpected cell type (" + cellType + ")");
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.streaming;
|
package org.apache.poi.xssf.streaming;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
|
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||||
|
import org.apache.poi.ss.usermodel.DataFormat;
|
||||||
|
import org.apache.poi.ss.usermodel.ExtendedColor;
|
||||||
|
import org.apache.poi.ss.usermodel.Hyperlink;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
|
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
|
||||||
|
@ -27,13 +32,14 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
* based on the Streaming Workbook, and some on the related
|
* based on the Streaming Workbook, and some on the related
|
||||||
* regular XSSF Workbook
|
* regular XSSF Workbook
|
||||||
*/
|
*/
|
||||||
public class SXSSFCreationHelper extends XSSFCreationHelper {
|
public class SXSSFCreationHelper implements CreationHelper {
|
||||||
private static POILogger logger = POILogFactory.getLogger(SXSSFCreationHelper.class);
|
private static POILogger logger = POILogFactory.getLogger(SXSSFCreationHelper.class);
|
||||||
|
|
||||||
private SXSSFWorkbook wb;
|
private SXSSFWorkbook wb;
|
||||||
|
private XSSFCreationHelper helper;
|
||||||
|
|
||||||
public SXSSFCreationHelper(SXSSFWorkbook workbook) {
|
public SXSSFCreationHelper(SXSSFWorkbook workbook) {
|
||||||
super(workbook.getXSSFWorkbook());
|
this.helper = new XSSFCreationHelper(workbook.getXSSFWorkbook());
|
||||||
this.wb = workbook;
|
this.wb = workbook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,4 +51,18 @@ public class SXSSFCreationHelper extends XSSFCreationHelper {
|
||||||
public SXSSFFormulaEvaluator createFormulaEvaluator() {
|
public SXSSFFormulaEvaluator createFormulaEvaluator() {
|
||||||
return new SXSSFFormulaEvaluator(wb);
|
return new SXSSFFormulaEvaluator(wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pass-through methods
|
||||||
|
public DataFormat createDataFormat() {
|
||||||
|
return helper.createDataFormat();
|
||||||
|
}
|
||||||
|
public Hyperlink createHyperlink(int type) {
|
||||||
|
return helper.createHyperlink(type);
|
||||||
|
}
|
||||||
|
public ExtendedColor createExtendedColor() {
|
||||||
|
return helper.createExtendedColor();
|
||||||
|
}
|
||||||
|
public ClientAnchor createClientAnchor() {
|
||||||
|
return helper.createClientAnchor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
|
import org.apache.poi.xssf.usermodel.BaseXSSFFormulaEvaluator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Streaming-specific Formula Evaluator, which is able to
|
* Streaming-specific Formula Evaluator, which is able to
|
||||||
* lookup cells within the current Window.
|
* lookup cells within the current Window.
|
||||||
*/
|
*/
|
||||||
public class SXSSFFormulaEvaluator extends XSSFFormulaEvaluator {
|
public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
|
||||||
private static POILogger logger = POILogFactory.getLogger(SXSSFFormulaEvaluator.class);
|
private static POILogger logger = POILogFactory.getLogger(SXSSFFormulaEvaluator.class);
|
||||||
|
|
||||||
private SXSSFWorkbook wb;
|
private SXSSFWorkbook wb;
|
||||||
|
@ -43,7 +43,7 @@ public class SXSSFFormulaEvaluator extends XSSFFormulaEvaluator {
|
||||||
this(workbook, new WorkbookEvaluator(SXSSFEvaluationWorkbook.create(workbook), stabilityClassifier, udfFinder));
|
this(workbook, new WorkbookEvaluator(SXSSFEvaluationWorkbook.create(workbook), stabilityClassifier, udfFinder));
|
||||||
}
|
}
|
||||||
private SXSSFFormulaEvaluator(SXSSFWorkbook workbook, WorkbookEvaluator bookEvaluator) {
|
private SXSSFFormulaEvaluator(SXSSFWorkbook workbook, WorkbookEvaluator bookEvaluator) {
|
||||||
super(workbook.getXSSFWorkbook(), bookEvaluator);
|
super(bookEvaluator);
|
||||||
this.wb = workbook;
|
this.wb = workbook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,26 @@ public class SXSSFFormulaEvaluator extends XSSFFormulaEvaluator {
|
||||||
return new SXSSFEvaluationCell((SXSSFCell)cell);
|
return new SXSSFEvaluationCell((SXSSFCell)cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If cell contains formula, it evaluates the formula, and
|
||||||
|
* puts the formula result back into the cell, in place
|
||||||
|
* of the old formula.
|
||||||
|
* Else if cell does not contain formula, this method leaves
|
||||||
|
* the cell unchanged.
|
||||||
|
* Note that the same instance of SXSSFCell is returned to
|
||||||
|
* allow chained calls like:
|
||||||
|
* <pre>
|
||||||
|
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
|
||||||
|
* </pre>
|
||||||
|
* Be aware that your cell value will be changed to hold the
|
||||||
|
* result of the formula. If you simply want the formula
|
||||||
|
* value computed for you, use {@link #evaluateFormulaCell(org.apache.poi.ss.usermodel.Cell)} }
|
||||||
|
*/
|
||||||
|
public SXSSFCell evaluateInCell(Cell cell) {
|
||||||
|
doEvaluateInCell(cell);
|
||||||
|
return (SXSSFCell)cell;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For active worksheets only, will loop over rows and
|
* For active worksheets only, will loop over rows and
|
||||||
* cells, evaluating formula cells there.
|
* cells, evaluating formula cells there.
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.poi.xssf.SXSSFITestDataProvider;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,51 +47,6 @@ public class TestSXSSFCell extends BaseTestXCell {
|
||||||
SXSSFITestDataProvider.instance.cleanup();
|
SXSSFITestDataProvider.instance.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this test involves evaluation of formulas which isn't supported for SXSSF
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void testConvertStringFormulaCell() {
|
|
||||||
try {
|
|
||||||
super.testConvertStringFormulaCell();
|
|
||||||
fail("expected exception");
|
|
||||||
} catch (IllegalArgumentException e){
|
|
||||||
assertEquals(
|
|
||||||
"Unexpected type of cell: class org.apache.poi.xssf.streaming.SXSSFCell. " +
|
|
||||||
"Only XSSFCells can be evaluated.", e.getMessage());
|
|
||||||
} catch (ClassCastException e) {} // TODO Temporary workaround during #58200
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this test involves evaluation of formulas which isn't supported for SXSSF
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void testSetTypeStringOnFormulaCell() {
|
|
||||||
try {
|
|
||||||
super.testSetTypeStringOnFormulaCell();
|
|
||||||
fail("expected exception");
|
|
||||||
} catch (IllegalArgumentException e){
|
|
||||||
assertEquals(
|
|
||||||
"Unexpected type of cell: class org.apache.poi.xssf.streaming.SXSSFCell. " +
|
|
||||||
"Only XSSFCells can be evaluated.", e.getMessage());
|
|
||||||
} catch (ClassCastException e) {} // TODO Temporary workaround during #58200
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this test involves evaluation of formulas which isn't supported for SXSSF
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void testGetErrorCellValueFromFormulaCell() {
|
|
||||||
try {
|
|
||||||
super.testConvertStringFormulaCell();
|
|
||||||
fail("expected exception");
|
|
||||||
} catch (IllegalArgumentException e){
|
|
||||||
assertEquals(
|
|
||||||
"Unexpected type of cell: class org.apache.poi.xssf.streaming.SXSSFCell. " +
|
|
||||||
"Only XSSFCells can be evaluated.", e.getMessage());
|
|
||||||
} catch (ClassCastException e) {} // TODO Temporary workaround during #58200
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPreserveSpaces() throws IOException {
|
public void testPreserveSpaces() throws IOException {
|
||||||
String[] samplesWithSpaces = {
|
String[] samplesWithSpaces = {
|
||||||
" POI",
|
" POI",
|
||||||
|
|
Loading…
Reference in New Issue