update getCellType to return CellType enum instead of int

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808700 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2017-09-18 13:26:16 +00:00
parent d9b63eb569
commit d4486af6de
26 changed files with 237 additions and 438 deletions

View File

@ -321,7 +321,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
// Only output if requested // Only output if requested
outputContents = _includeBlankCells; outputContents = _includeBlankCells;
} else { } else {
switch(cell.getCellTypeEnum()) { switch(cell.getCellType()) {
case STRING: case STRING:
text.append(cell.getRichStringCellValue().getString()); text.append(cell.getRichStringCellValue().getString());
break; break;
@ -338,7 +338,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
if(!_shouldEvaluateFormulas) { if(!_shouldEvaluateFormulas) {
text.append(cell.getCellFormula()); text.append(cell.getCellFormula());
} else { } else {
switch(cell.getCachedFormulaResultTypeEnum()) { switch(cell.getCachedFormulaResultType()) {
case STRING: case STRING:
HSSFRichTextString str = cell.getRichStringCellValue(); HSSFRichTextString str = cell.getRichStringCellValue();
if(str != null && str.length() > 0) { if(str != null && str.length() > 0) {
@ -359,13 +359,13 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
text.append(ErrorEval.getText(cell.getErrorCellValue())); text.append(ErrorEval.getText(cell.getErrorCellValue()));
break; break;
default: default:
throw new IllegalStateException("Unexpected cell cached formula result type: " + cell.getCachedFormulaResultTypeEnum()); throw new IllegalStateException("Unexpected cell cached formula result type: " + cell.getCachedFormulaResultType());
} }
} }
break; break;
default: default:
throw new RuntimeException("Unexpected cell type (" + cell.getCellTypeEnum() + ")"); throw new RuntimeException("Unexpected cell type (" + cell.getCellType() + ")");
} }
// Output the comment, if requested and exists // Output the comment, if requested and exists

View File

@ -256,22 +256,6 @@ public class HSSFCell implements Cell {
return new CellAddress(this); return new CellAddress(this);
} }
/**
* Set the cells type (numeric, formula or string).
* If the cell currently contains a value, the value will
* be converted to match the new type, if possible.
* @see CellType#NUMERIC
* @see CellType#STRING
* @see CellType#FORMULA
* @see CellType#BLANK
* @see CellType#BOOLEAN
* @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
*/
@Override
public void setCellType(int cellType) {
setCellType(CellType.forInt(cellType));
}
/** /**
* Set the cells type (numeric, formula or string). * Set the cells type (numeric, formula or string).
* If the cell currently contains a value, the value will * If the cell currently contains a value, the value will
@ -444,26 +428,23 @@ public class HSSFCell implements Cell {
/** /**
* get the cells type (numeric, formula or string) * get the cells type (numeric, formula or string)
*
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
* @deprecated 3.15. Will be return a {@link CellType} enum in the future.
*/ */
@Override @Override
public int getCellType() public CellType getCellType()
{ {
return getCellTypeEnum().getCode(); return _cellType;
} }
/** /**
* get the cells type (numeric, formula or string) * get the cells type (numeric, formula or string)
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() public CellType getCellTypeEnum()
{ {
return _cellType; return getCellType();
} }
/** /**
@ -1227,7 +1208,6 @@ public class HSSFCell implements Cell {
* The purpose of this method is to validate the cell state prior to modification. * The purpose of this method is to validate the cell state prior to modification.
* </p> * </p>
* *
* @see #setCellType(int)
* @see #setCellFormula(String) * @see #setCellFormula(String)
* @see HSSFRow#removeCell(org.apache.poi.ss.usermodel.Cell) * @see HSSFRow#removeCell(org.apache.poi.ss.usermodel.Cell)
* @see org.apache.poi.hssf.usermodel.HSSFSheet#removeRow(org.apache.poi.ss.usermodel.Row) * @see org.apache.poi.hssf.usermodel.HSSFSheet#removeRow(org.apache.poi.ss.usermodel.Row)

View File

@ -53,24 +53,21 @@ final class HSSFEvaluationCell implements EvaluationCell {
return _cell.getBooleanCellValue(); return _cell.getBooleanCellValue();
} }
/** /**
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type * @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/ */
@Override @Override
public int getCellType() { public CellType getCellType() {
return _cell.getCellType(); return _cell.getCellType();
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() {
return _cell.getCellTypeEnum(); return getCellType();
} }
@Override @Override
public int getColumnIndex() { public int getColumnIndex() {

View File

@ -435,8 +435,8 @@ public class CellFormat {
/** /**
* Returns the ultimate cell type, following the results of formulas. If * Returns the ultimate cell type, following the results of formulas. If
* the cell is a {@link CellType#FORMULA}, this returns the result of * the cell is a {@link CellType#FORMULA}, this returns the result of
* {@link Cell#getCachedFormulaResultTypeEnum()}. Otherwise this returns the * {@link Cell#getCachedFormulaResultType()}. Otherwise this returns the
* result of {@link Cell#getCellTypeEnum()}. * result of {@link Cell#getCellType()}.
* *
* Will return {@link CellType} in a future version of POI. * Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code. * For forwards compatibility, do not hard-code cell type literals in your code.
@ -453,8 +453,8 @@ public class CellFormat {
/** /**
* Returns the ultimate cell type, following the results of formulas. If * Returns the ultimate cell type, following the results of formulas. If
* the cell is a {@link CellType#FORMULA}, this returns the result of * the cell is a {@link CellType#FORMULA}, this returns the result of
* {@link Cell#getCachedFormulaResultTypeEnum()}. Otherwise this returns the * {@link Cell#getCachedFormulaResultType()}. Otherwise this returns the
* result of {@link Cell#getCellTypeEnum()}. * result of {@link Cell#getCellType()}.
* *
* @param cell The cell. * @param cell The cell.
* *
@ -464,9 +464,9 @@ public class CellFormat {
* Will be deleted when we make the CellType enum transition. See bug 59791. * Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
public static CellType ultimateTypeEnum(Cell cell) { public static CellType ultimateTypeEnum(Cell cell) {
CellType type = cell.getCellTypeEnum(); CellType type = cell.getCellType();
if (type == CellType.FORMULA) if (type == CellType.FORMULA)
return cell.getCachedFormulaResultTypeEnum(); return cell.getCachedFormulaResultType();
else else
return type; return type;
} }

View File

@ -39,19 +39,13 @@ public interface EvaluationCell {
EvaluationSheet getSheet(); EvaluationSheet getSheet();
int getRowIndex(); int getRowIndex();
int getColumnIndex(); int getColumnIndex();
/** CellType getCellType();
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
int getCellType();
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
CellType getCellTypeEnum(); CellType getCellTypeEnum();
double getNumericCellValue(); double getNumericCellValue();

View File

@ -623,12 +623,12 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
private ValueAndFormat getCellValue(Cell cell) { private ValueAndFormat getCellValue(Cell cell) {
if (cell != null) { if (cell != null) {
final CellType type = cell.getCellTypeEnum(); final CellType type = cell.getCellType();
if (type == CellType.NUMERIC || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.NUMERIC) ) { if (type == CellType.NUMERIC || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.NUMERIC) ) {
return new ValueAndFormat(new Double(cell.getNumericCellValue()), cell.getCellStyle().getDataFormatString()); return new ValueAndFormat(new Double(cell.getNumericCellValue()), cell.getCellStyle().getDataFormatString());
} else if (type == CellType.STRING || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.STRING) ) { } else if (type == CellType.STRING || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.STRING) ) {
return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString()); return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
} else if (type == CellType.BOOLEAN || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.BOOLEAN) ) { } else if (type == CellType.BOOLEAN || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.BOOLEAN) ) {
return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString()); return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
} }
} }

View File

@ -105,25 +105,21 @@ final class ForkedEvaluationCell implements EvaluationCell {
throw new RuntimeException("Wrong data type (" + _cellType + ")"); throw new RuntimeException("Wrong data type (" + _cellType + ")");
} }
} }
/**
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override @Override
public int getCellType() { public CellType getCellType() {
return _cellType.getCode(); return _cellType;
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791. * Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() {
return _cellType; return getCellType();
} }
@Override @Override
public boolean getBooleanCellValue() { public boolean getBooleanCellValue() {

View File

@ -41,66 +41,6 @@ import org.apache.poi.util.Removal;
*/ */
public interface Cell { public interface Cell {
/**
* Numeric Cell type (0)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#NUMERIC} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_NUMERIC = 0; //CellType.NUMERIC.getCode();
/**
* String Cell type (1)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#STRING} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_STRING = 1; //CellType.STRING.getCode();
/**
* Formula Cell type (2)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#FORMULA} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_FORMULA = 2; //CellType.FORMULA.getCode();
/**
* Blank Cell type (3)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#BLANK} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_BLANK = 3; //CellType.BLANK.getCode();
/**
* Boolean Cell type (4)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#BOOLEAN} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_BOOLEAN = 4; //CellType.BOOLEAN.getCode();
/**
* Error Cell type (5)
* @see #setCellType(int)
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#ERROR} instead.
*/
@Deprecated
@Removal(version="4.0")
int CELL_TYPE_ERROR = 5; //CellType.ERROR.getCode();
/** /**
* Returns column index of this cell * Returns column index of this cell
* *
@ -129,29 +69,6 @@ public interface Cell {
*/ */
Row getRow(); Row getRow();
/**
* Set the cells type (numeric, formula or string).
* <p>If the cell currently contains a value, the value will
* be converted to match the new type, if possible. Formatting
* is generally lost in the process however.</p>
* <p>If what you want to do is get a String value for your
* numeric cell, <i>stop!</i>. This is not the way to do it.
* Instead, for fetching the string value of a numeric or boolean
* or date cell, use {@link DataFormatter} instead.</p>
*
* @throws IllegalArgumentException if the specified cell type is invalid
* @throws IllegalStateException if the current value cannot be converted to the new type
* @see CellType#NUMERIC
* @see CellType#STRING
* @see CellType#FORMULA
* @see CellType#BLANK
* @see CellType#BOOLEAN
* @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
*/
@Deprecated
@Removal(version="4.0")
void setCellType(int cellType);
/** /**
* Set the cells type (numeric, formula or string). * Set the cells type (numeric, formula or string).
* <p>If the cell currently contains a value, the value will * <p>If the cell currently contains a value, the value will
@ -170,14 +87,9 @@ public interface Cell {
/** /**
* Return the cell type. * Return the cell type.
* *
* Will return {@link CellType} in version 4.0 of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type * @return the cell type
* @deprecated POI 3.15. Will return a {@link CellType} enum in the future.
*/ */
@Deprecated CellType getCellType();
int getCellType();
/** /**
* Return the cell type. * Return the cell type.
@ -186,6 +98,7 @@ public interface Cell {
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791. * Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/ */
@Deprecated
@Removal(version="4.2") @Removal(version="4.2")
CellType getCellTypeEnum(); CellType getCellTypeEnum();

View File

@ -88,26 +88,19 @@ public final class CellValue {
* *
* @return the cell type * @return the cell type
* @since POI 3.15 * @since POI 3.15
* Will be renamed to <code>getCellTypeEnum()</code> when we make the CellType enum transition in POI 4.0. See bug 59791. * @deprecated use <code>getCellType</code> instead
*/ */
@Deprecated
@Removal(version="4.2") @Removal(version="4.2")
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() { return getCellType(); }
return _cellType;
}
/** /**
* Return the cell type. * Return the cell type.
* *
* Will return {@link CellType} in version 4.0 of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type * @return the cell type
*
* @deprecated POI 3.15. Use {@link #getCellTypeEnum()} instead.
*/ */
@Deprecated public CellType getCellType() {
public int getCellType() { return _cellType;
return _cellType.getCode();
} }
/** /**

View File

@ -162,19 +162,19 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor
Cell cell = ri.next(); Cell cell = ri.next();
// Is it a formula one? // Is it a formula one?
if(cell.getCellTypeEnum() == CellType.FORMULA) { if(cell.getCellType() == CellType.FORMULA) {
if (formulasNotResults) { if (formulasNotResults) {
String contents = cell.getCellFormula(); String contents = cell.getCellFormula();
checkMaxTextSize(text, contents); checkMaxTextSize(text, contents);
text.append(contents); text.append(contents);
} else { } else {
if (cell.getCachedFormulaResultTypeEnum() == CellType.STRING) { if (cell.getCachedFormulaResultType() == CellType.STRING) {
handleStringCell(text, cell); handleStringCell(text, cell);
} else { } else {
handleNonStringCell(text, cell, formatter); handleNonStringCell(text, cell, formatter);
} }
} }
} else if(cell.getCellTypeEnum() == CellType.STRING) { } else if(cell.getCellType() == CellType.STRING) {
handleStringCell(text, cell); handleStringCell(text, cell);
} else { } else {
handleNonStringCell(text, cell, formatter); handleNonStringCell(text, cell, formatter);
@ -236,9 +236,9 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor
} }
private void handleNonStringCell(StringBuffer text, Cell cell, DataFormatter formatter) { private void handleNonStringCell(StringBuffer text, Cell cell, DataFormatter formatter) {
CellType type = cell.getCellTypeEnum(); CellType type = cell.getCellType();
if (type == CellType.FORMULA) { if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultTypeEnum(); type = cell.getCachedFormulaResultType();
} }
if (type == CellType.NUMERIC) { if (type == CellType.NUMERIC) {

View File

@ -113,24 +113,6 @@ public class SXSSFCell implements Cell {
return _row; return _row;
} }
/**
* Set the cells type (numeric, formula or string)
*
* @throws IllegalArgumentException if the specified cell type is invalid
* @see CellType#NUMERIC
* @see CellType#STRING
* @see CellType#FORMULA
* @see CellType#BLANK
* @see CellType#BOOLEAN
* @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Override
public void setCellType(int cellType)
{
ensureType(CellType.forInt(cellType));
}
/** /**
* Set the cells type (numeric, formula or string) * Set the cells type (numeric, formula or string)
* *
@ -146,12 +128,11 @@ public class SXSSFCell implements Cell {
* Return the cell type. * Return the cell type.
* *
* @return the cell type * @return the cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/ */
@Override @Override
public int getCellType() public CellType getCellType()
{ {
return getCellTypeEnum().getCode(); return _value.getType();
} }
/** /**
@ -159,12 +140,14 @@ public class SXSSFCell implements Cell {
* *
* @return the cell type * @return the cell type
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791. * @deprecated use <code>getCellType</code> instead
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() public CellType getCellTypeEnum()
{ {
return _value.getType(); return getCellType();
} }
/** /**
@ -188,7 +171,7 @@ public class SXSSFCell implements Cell {
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
* on the cached value of the formula * on the cached value of the formula
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated use <code>getCachedFormulaResultTypeEnum</code> instead * @deprecated use <code>getCachedFormulaResultType</code> instead
*/ */
@Deprecated @Deprecated
@Removal(version = "4.2") @Removal(version = "4.2")
@ -999,7 +982,7 @@ public class SXSSFCell implements Cell {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellTypeEnum();
if (cellType == CellType.FORMULA) { if (cellType == CellType.FORMULA) {
cellType = getCachedFormulaResultTypeEnum(); cellType = getCachedFormulaResultType();
} }
switch (cellType) { switch (cellType) {

View File

@ -55,21 +55,19 @@ final class SXSSFEvaluationCell implements EvaluationCell {
return _cell.getBooleanCellValue(); return _cell.getBooleanCellValue();
} }
/** /**
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type * @return cell type
* @deprecated 3.17. Will return a {@link CellType} enum in the future.
*/ */
@Override @Override
public int getCellType() { public CellType getCellType() {
return _cell.getCellType(); return _cell.getCellType();
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated use <code>getCellType</code> instead
* Will be deleted when we make the CellType enum transition. See bug 59791. * Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
@Internal(since="POI 3.15 beta 3") @Internal(since="POI 3.15 beta 3")
@Override @Override
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() {
@ -115,7 +113,7 @@ final class SXSSFEvaluationCell implements EvaluationCell {
*/ */
@Override @Override
public CellType getCachedFormulaResultType() { public CellType getCachedFormulaResultType() {
return _cell.getCachedFormulaResultTypeEnum(); return _cell.getCachedFormulaResultType();
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3

View File

@ -139,11 +139,11 @@ public final class XSSFCell implements Cell {
// Copy cell value (cell type is updated implicitly) // Copy cell value (cell type is updated implicitly)
if (policy.isCopyCellValue()) { if (policy.isCopyCellValue()) {
if (srcCell != null) { if (srcCell != null) {
CellType copyCellType = srcCell.getCellTypeEnum(); CellType copyCellType = srcCell.getCellType();
if (copyCellType == CellType.FORMULA && !policy.isCopyCellFormula()) { if (copyCellType == CellType.FORMULA && !policy.isCopyCellFormula()) {
// Copy formula result as value // Copy formula result as value
// FIXME: Cached value may be stale // FIXME: Cached value may be stale
copyCellType = srcCell.getCachedFormulaResultTypeEnum(); copyCellType = srcCell.getCachedFormulaResultType();
} }
switch (copyCellType) { switch (copyCellType) {
case NUMERIC: case NUMERIC:
@ -172,7 +172,7 @@ public final class XSSFCell implements Cell {
break; break;
default: default:
throw new IllegalArgumentException("Invalid cell type " + srcCell.getCellTypeEnum()); throw new IllegalArgumentException("Invalid cell type " + srcCell.getCellType());
} }
} else { //srcCell is null } else { //srcCell is null
setBlank(); setBlank();
@ -238,12 +238,12 @@ public final class XSSFCell implements Cell {
* For strings, numbers, and errors, we throw an exception. For blank cells we return a false. * For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
* </p> * </p>
* @return the value of the cell as a boolean * @return the value of the cell as a boolean
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} * @throws IllegalStateException if the cell type returned by {@link #getCellType()}
* is not {@link CellType#BOOLEAN}, {@link CellType#BLANK} or {@link CellType#FORMULA} * is not {@link CellType#BOOLEAN}, {@link CellType#BLANK} or {@link CellType#FORMULA}
*/ */
@Override @Override
public boolean getBooleanCellValue() { public boolean getBooleanCellValue() {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
switch(cellType) { switch(cellType) {
case BLANK: case BLANK:
return false; return false;
@ -277,13 +277,13 @@ public final class XSSFCell implements Cell {
* For formulas or error cells we return the precalculated value; * For formulas or error cells we return the precalculated value;
* </p> * </p>
* @return the value of the cell as a number * @return the value of the cell as a number
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is {@link CellType#STRING} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
* @see DataFormatter for turning this number into a string similar to that which Excel would render this number as. * @see DataFormatter for turning this number into a string similar to that which Excel would render this number as.
*/ */
@Override @Override
public double getNumericCellValue() { public double getNumericCellValue() {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
switch(cellType) { switch(cellType) {
case BLANK: case BLANK:
return 0.0; return 0.0;
@ -357,7 +357,7 @@ public final class XSSFCell implements Cell {
*/ */
@Override @Override
public XSSFRichTextString getRichStringCellValue() { public XSSFRichTextString getRichStringCellValue() {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
XSSFRichTextString rt; XSSFRichTextString rt;
switch (cellType) { switch (cellType) {
case BLANK: case BLANK:
@ -436,7 +436,7 @@ public final class XSSFCell implements Cell {
throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters"); throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
} }
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
switch (cellType){ switch (cellType){
case FORMULA: case FORMULA:
_cell.setV(str.getString()); _cell.setV(str.getString());
@ -461,7 +461,7 @@ public final class XSSFCell implements Cell {
* Return a formula for the cell, for example, <code>SUM(C4:E4)</code> * Return a formula for the cell, for example, <code>SUM(C4:E4)</code>
* *
* @return a formula for the cell * @return a formula for the cell
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is not {@link CellType#FORMULA} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not {@link CellType#FORMULA}
*/ */
@Override @Override
public String getCellFormula() { public String getCellFormula() {
@ -474,10 +474,10 @@ public final class XSSFCell implements Cell {
* *
* @param fpb evaluation workbook for reuse, if available, or null to create a new one as needed * @param fpb evaluation workbook for reuse, if available, or null to create a new one as needed
* @return a formula for the cell * @return a formula for the cell
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is not {@link CellType#FORMULA} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not {@link CellType#FORMULA}
*/ */
protected String getCellFormula(XSSFEvaluationWorkbook fpb) { protected String getCellFormula(XSSFEvaluationWorkbook fpb) {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
if(cellType != CellType.FORMULA) { if(cellType != CellType.FORMULA) {
throw typeMismatch(CellType.FORMULA, cellType, false); throw typeMismatch(CellType.FORMULA, cellType, false);
} }
@ -676,19 +676,22 @@ public final class XSSFCell implements Cell {
} }
/** /**
* Return the cell type. * Return the cell type. Tables in an array formula return
* * {@link CellType#FORMULA} for all cells, even though the formula is only defined
* Will return {@link CellType} in a future version of POI. * in the OOXML file for the top left cell of the array.
* For forwards compatibility, do not hard-code cell type literals in your code. * <p>
* NOTE: POI does not support data table formulas.
* Cells in a data table appear to POI as plain cells typed from their cached value.
* *
* @return the cell type * @return the cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/ */
@Deprecated
@Override @Override
@Removal(version="3.17") public CellType getCellType() {
public int getCellType() { if (isFormulaCell()) {
return getCellTypeEnum().getCode(); return CellType.FORMULA;
}
return getBaseCellType(true);
} }
/** /**
@ -701,15 +704,13 @@ public final class XSSFCell implements Cell {
* *
* @return the cell type * @return the cell type
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791. * @deprecated use <code>getCellType</code> instead
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() {
if (isFormulaCell()) { return getCellType();
return CellType.FORMULA;
}
return getBaseCellType(true);
} }
/** /**
@ -777,13 +778,13 @@ public final class XSSFCell implements Cell {
* For strings we throw an exception. For blank cells we return a null. * For strings we throw an exception. For blank cells we return a null.
* </p> * </p>
* @return the value of the cell as a date * @return the value of the cell as a date
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is {@link CellType#STRING} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
* @see DataFormatter for formatting this date into a string similar to how excel does. * @see DataFormatter for formatting this date into a string similar to how excel does.
*/ */
@Override @Override
public Date getDateCellValue() { public Date getDateCellValue() {
if (getCellTypeEnum() == CellType.BLANK) { if (getCellType() == CellType.BLANK) {
return null; return null;
} }
@ -842,7 +843,7 @@ public final class XSSFCell implements Cell {
* Returns the error message, such as #VALUE! * Returns the error message, such as #VALUE!
* *
* @return the error message such as #VALUE! * @return the error message such as #VALUE!
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} isn't {@link CellType#ERROR} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't {@link CellType#ERROR}
* @see FormulaError * @see FormulaError
*/ */
public String getErrorCellString() throws IllegalStateException { public String getErrorCellString() throws IllegalStateException {
@ -861,7 +862,7 @@ public final class XSSFCell implements Cell {
* </p> * </p>
* *
* @return the value of the cell as an error code * @return the value of the cell as an error code
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} isn't {@link CellType #ERROR} * @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't {@link CellType #ERROR}
* @see FormulaError * @see FormulaError
*/ */
@Override @Override
@ -938,24 +939,6 @@ public final class XSSFCell implements Cell {
_cell.setR(ref); _cell.setR(ref);
} }
/**
* Set the cells type (numeric, formula or string)
*
* @throws IllegalArgumentException if the specified cell type is invalid
* @see CellType#NUMERIC
* @see CellType#STRING
* @see CellType#FORMULA
* @see CellType#BLANK
* @see CellType#BOOLEAN
* @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
*/
@Deprecated
@Override
@Removal(version="3.17")
public void setCellType(int cellType) {
setCellType(CellType.forInt(cellType));
}
/** /**
* Set the cells type (numeric, formula or string) * Set the cells type (numeric, formula or string)
* *
@ -963,7 +946,7 @@ public final class XSSFCell implements Cell {
*/ */
@Override @Override
public void setCellType(CellType cellType) { public void setCellType(CellType cellType) {
CellType prevType = getCellTypeEnum(); CellType prevType = getCellType();
if(isPartOfArrayFormulaGroup()){ if(isPartOfArrayFormulaGroup()){
notifyArrayFormulaChanging(); notifyArrayFormulaChanging();
@ -1028,7 +1011,7 @@ public final class XSSFCell implements Cell {
*/ */
@Override @Override
public String toString() { public String toString() {
switch (getCellTypeEnum()) { switch (getCellType()) {
case NUMERIC: case NUMERIC:
if (DateUtil.isCellDateFormatted(this)) { if (DateUtil.isCellDateFormatted(this)) {
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale()); DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale());
@ -1047,7 +1030,7 @@ public final class XSSFCell implements Cell {
case ERROR: case ERROR:
return ErrorEval.getText(getErrorCellValue()); return ErrorEval.getText(getErrorCellValue());
default: default:
return "Unknown Cell Type: " + getCellTypeEnum(); return "Unknown Cell Type: " + getCellType();
} }
} }
@ -1196,10 +1179,10 @@ public final class XSSFCell implements Cell {
* Usually the caller is calling setCellType() with the intention of calling * Usually the caller is calling setCellType() with the intention of calling
* setCellValue(boolean) straight afterwards. This method only exists to give * setCellValue(boolean) straight afterwards. This method only exists to give
* the cell a somewhat reasonable value until the setCellValue() call (if at all). * the cell a somewhat reasonable value until the setCellValue() call (if at all).
* TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this * TODO - perhaps a method like setCellTypeAndValue(CellType, Object) should be introduced to avoid this
*/ */
private boolean convertCellValueToBoolean() { private boolean convertCellValueToBoolean() {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
if (cellType == CellType.FORMULA) { if (cellType == CellType.FORMULA) {
cellType = getBaseCellType(false); cellType = getBaseCellType(false);
@ -1227,7 +1210,7 @@ public final class XSSFCell implements Cell {
} }
private String convertCellValueToString() { private String convertCellValueToString() {
CellType cellType = getCellTypeEnum(); CellType cellType = getCellType();
switch (cellType) { switch (cellType) {
case BLANK: case BLANK:
@ -1312,7 +1295,7 @@ public final class XSSFCell implements Cell {
* The purpose of this method is to validate the cell state prior to modification. * The purpose of this method is to validate the cell state prior to modification.
* </p> * </p>
* *
* @see #setCellType(int) * @see #setCellType(CellType)
* @see #setCellFormula(String) * @see #setCellFormula(String)
* @see XSSFRow#removeCell(org.apache.poi.ss.usermodel.Cell) * @see XSSFRow#removeCell(org.apache.poi.ss.usermodel.Cell)
* @see org.apache.poi.xssf.usermodel.XSSFSheet#removeRow(org.apache.poi.ss.usermodel.Row) * @see org.apache.poi.xssf.usermodel.XSSFSheet#removeRow(org.apache.poi.ss.usermodel.Row)

View File

@ -56,24 +56,21 @@ final class XSSFEvaluationCell implements EvaluationCell {
return _cell.getBooleanCellValue(); return _cell.getBooleanCellValue();
} }
/** /**
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type * @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/ */
@Override @Override
public int getCellType() { public CellType getCellType() {
return _cell.getCellType(); return _cell.getCellType();
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated use <code>getCellType</code> instead
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated
@Removal(version = "4.2")
@Override @Override
public CellType getCellTypeEnum() { public CellType getCellTypeEnum() {
return _cell.getCellTypeEnum(); return getCellType();
} }
@Override @Override
public int getColumnIndex() { public int getColumnIndex() {
@ -115,11 +112,11 @@ final class XSSFEvaluationCell implements EvaluationCell {
*/ */
@Override @Override
public CellType getCachedFormulaResultType() { public CellType getCachedFormulaResultType() {
return _cell.getCachedFormulaResultTypeEnum(); return _cell.getCachedFormulaResultType();
} }
/** /**
* @since POI 3.15 beta 3 * @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. * @deprecated use <code>getCachedFormulaResultType</code> instead
* Will be deleted when we make the CellType enum transition. See bug 59791. * Will be deleted when we make the CellType enum transition. See bug 59791.
*/ */
@Deprecated @Deprecated

View File

@ -121,14 +121,14 @@ public abstract class AbstractExcelConverter
protected boolean isTextEmpty( HSSFCell cell ) protected boolean isTextEmpty( HSSFCell cell )
{ {
final String value; final String value;
switch ( cell.getCellTypeEnum() ) switch ( cell.getCellType() )
{ {
case STRING: case STRING:
// XXX: enrich // XXX: enrich
value = cell.getRichStringCellValue().getString(); value = cell.getRichStringCellValue().getString();
break; break;
case FORMULA: case FORMULA:
switch ( cell.getCachedFormulaResultTypeEnum() ) switch ( cell.getCachedFormulaResultType() )
{ {
case STRING: case STRING:
HSSFRichTextString str = cell.getRichStringCellValue(); HSSFRichTextString str = cell.getRichStringCellValue();

View File

@ -209,14 +209,14 @@ public class ExcelToFoConverter extends AbstractExcelConverter
final HSSFCellStyle cellStyle = cell.getCellStyle(); final HSSFCellStyle cellStyle = cell.getCellStyle();
String value; String value;
switch ( cell.getCellTypeEnum() ) switch ( cell.getCellType() )
{ {
case STRING: case STRING:
// XXX: enrich // XXX: enrich
value = cell.getRichStringCellValue().getString(); value = cell.getRichStringCellValue().getString();
break; break;
case FORMULA: case FORMULA:
switch ( cell.getCachedFormulaResultTypeEnum() ) switch ( cell.getCachedFormulaResultType() )
{ {
case STRING: case STRING:
HSSFRichTextString str = cell.getRichStringCellValue(); HSSFRichTextString str = cell.getRichStringCellValue();
@ -245,7 +245,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter
logger.log( logger.log(
POILogger.WARN, POILogger.WARN,
"Unexpected cell cachedFormulaResultType (" "Unexpected cell cachedFormulaResultType ("
+ cell.getCachedFormulaResultTypeEnum() + ")" ); + cell.getCachedFormulaResultType() + ")" );
value = ExcelToHtmlUtils.EMPTY; value = ExcelToHtmlUtils.EMPTY;
break; break;
} }
@ -264,7 +264,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter
break; break;
default: default:
logger.log( POILogger.WARN, logger.log( POILogger.WARN,
"Unexpected cell type (" + cell.getCellTypeEnum() + ")" ); "Unexpected cell type (" + cell.getCellType() + ")" );
return true; return true;
} }

View File

@ -322,14 +322,14 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
final HSSFCellStyle cellStyle = cell.getCellStyle(); final HSSFCellStyle cellStyle = cell.getCellStyle();
String value; String value;
switch ( cell.getCellTypeEnum() ) switch ( cell.getCellType() )
{ {
case STRING: case STRING:
// XXX: enrich // XXX: enrich
value = cell.getRichStringCellValue().getString(); value = cell.getRichStringCellValue().getString();
break; break;
case FORMULA: case FORMULA:
switch ( cell.getCachedFormulaResultTypeEnum() ) switch ( cell.getCachedFormulaResultType() )
{ {
case STRING: case STRING:
HSSFRichTextString str = cell.getRichStringCellValue(); HSSFRichTextString str = cell.getRichStringCellValue();
@ -358,7 +358,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
logger.log( logger.log(
POILogger.WARN, POILogger.WARN,
"Unexpected cell cachedFormulaResultType (" "Unexpected cell cachedFormulaResultType ("
+ cell.getCachedFormulaResultTypeEnum() + ")" ); + cell.getCachedFormulaResultType() + ")" );
value = ExcelToHtmlUtils.EMPTY; value = ExcelToHtmlUtils.EMPTY;
break; break;
} }
@ -377,7 +377,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
break; break;
default: default:
logger.log( POILogger.WARN, logger.log( POILogger.WARN,
"Unexpected cell type (" + cell.getCellTypeEnum() + ")" ); "Unexpected cell type (" + cell.getCellType() + ")" );
return true; return true;
} }

View File

@ -507,7 +507,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFRow row = sheet.getRow(i); HSSFRow row = sheet.getRow(i);
if (row != null) { if (row != null) {
HSSFCell cell = row.getCell(0); HSSFCell cell = row.getCell(0);
assertEquals(CellType.STRING, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCellType());
count++; count++;
} }
} }
@ -1143,9 +1143,9 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Now evaluate, they should all be changed // Now evaluate, they should all be changed
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1); HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1);
eval.evaluateFormulaCellEnum(c1); eval.evaluateFormulaCell(c1);
eval.evaluateFormulaCellEnum(c2); eval.evaluateFormulaCell(c2);
eval.evaluateFormulaCellEnum(c3); eval.evaluateFormulaCell(c3);
// Check that the cells now contain // Check that the cells now contain
// the correct values // the correct values
@ -1192,14 +1192,14 @@ public final class TestBugs extends BaseTestBugzillaIssues {
} }
private static void confirmCachedValue(double expectedValue, HSSFCell cell) { private static void confirmCachedValue(double expectedValue, HSSFCell cell) {
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(expectedValue, cell.getNumericCellValue(), 0.0); assertEquals(expectedValue, cell.getNumericCellValue(), 0.0);
} }
private static void confirmCachedValue(String expectedValue, HSSFCell cell) { private static void confirmCachedValue(String expectedValue, HSSFCell cell) {
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.STRING, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
assertEquals(expectedValue, cell.getRichStringCellValue().getString()); assertEquals(expectedValue, cell.getRichStringCellValue().getString());
} }
@ -1313,7 +1313,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
s = wb.getSheet("OneVariable Table Completed"); s = wb.getSheet("OneVariable Table Completed");
r = s.getRow(3); r = s.getRow(3);
c = r.getCell(4); c = r.getCell(4);
assertEquals(CellType.FORMULA, c.getCellTypeEnum()); assertEquals(CellType.FORMULA, c.getCellType());
// TODO - check the formula once tables and // TODO - check the formula once tables and
// arrays are properly supported // arrays are properly supported
@ -1323,7 +1323,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
s = wb.getSheet("TwoVariable Table Example"); s = wb.getSheet("TwoVariable Table Example");
r = s.getRow(3); r = s.getRow(3);
c = r.getCell(4); c = r.getCell(4);
assertEquals(CellType.FORMULA, c.getCellTypeEnum()); assertEquals(CellType.FORMULA, c.getCellType());
// TODO - check the formula once tables and // TODO - check the formula once tables and
// arrays are properly supported // arrays are properly supported
@ -1850,26 +1850,26 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFRow row; HSSFRow row;
row = s.getRow(0); row = s.getRow(0);
assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(1); row = s.getRow(1);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("B1", row.getCell(1).getCellFormula()); assertEquals("B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(2); row = s.getRow(2);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); assertEquals("Sheet1!B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(3); row = s.getRow(3);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(4); row = s.getRow(4);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
@ -1899,31 +1899,31 @@ public final class TestBugs extends BaseTestBugzillaIssues {
s = wb2.getSheetAt(0); s = wb2.getSheetAt(0);
row = s.getRow(0); row = s.getRow(0);
assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(1); row = s.getRow(1);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("B1", row.getCell(1).getCellFormula()); assertEquals("B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(2); row = s.getRow(2);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); assertEquals("Sheet1!B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(3); row = s.getRow(3);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(4); row = s.getRow(4);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula()); assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(5); row = s.getRow(5);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0); assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);
@ -2795,12 +2795,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
} }
private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) { private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) {
assertEquals(CellType.FORMULA, intF.getCellTypeEnum()); assertEquals(CellType.FORMULA, intF.getCellType());
if (null == expectedResultOrNull) { if (null == expectedResultOrNull) {
assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, intF.getCachedFormulaResultType());
expectedResultOrNull = "#VALUE!"; expectedResultOrNull = "#VALUE!";
} else { } else {
assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultType());
} }
assertEquals(expectedFormula, intF.getCellFormula()); assertEquals(expectedFormula, intF.getCellFormula());
@ -3026,12 +3026,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0); Row row = sheet.getRow(0);
Cell cell = row.getCell(0); Cell cell = row.getCell(0);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("IF(TRUE,\"\",\"\")", cell.getCellFormula()); assertEquals("IF(TRUE,\"\",\"\")", cell.getCellFormula());
assertEquals("", cell.getStringCellValue()); assertEquals("", cell.getStringCellValue());
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
try { try {
assertNull(cell.getCellFormula()); assertNull(cell.getCellFormula());
fail("Should throw an exception here"); fail("Should throw an exception here");

View File

@ -55,7 +55,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
HSSFCell cell = sheet.getRow(8).getCell(0); HSSFCell cell = sheet.getRow(8).getCell(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(cell); CellValue cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(3.72, cv.getNumberValue(), 0.0); assertEquals(3.72, cv.getNumberValue(), 0.0);
wb.close(); wb.close();
} }
@ -127,7 +127,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
try { try {
value = hsf.evaluate(cellA1); value = hsf.evaluate(cellA1);
assertEquals(CellType.NUMERIC, value.getCellTypeEnum()); assertEquals(CellType.NUMERIC, value.getCellType());
assertEquals(5.33, value.getNumberValue(), 0.0); assertEquals(5.33, value.getNumberValue(), 0.0);
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -199,8 +199,8 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
// VLookup on a name in another file // VLookup on a name in another file
cell = wb1.getSheetAt(0).getRow(1).getCell(2); cell = wb1.getSheetAt(0).getRow(1).getCell(2);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(12.30, cell.getNumericCellValue(), 0.0001); assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
// WARNING - this is wrong! // WARNING - this is wrong!
// The file name should be showing, but bug #45970 is fixed // The file name should be showing, but bug #45970 is fixed
@ -210,8 +210,8 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
// Simple reference to a name in another file // Simple reference to a name in another file
cell = wb1.getSheetAt(0).getRow(1).getCell(4); cell = wb1.getSheetAt(0).getRow(1).getCell(4);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(36.90, cell.getNumericCellValue(), 0.0001); assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
// TODO Correct this! // TODO Correct this!
// The file name should be shown too, see bug #56742 // The file name should be shown too, see bug #56742
@ -237,14 +237,14 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
// Re-check VLOOKUP one // Re-check VLOOKUP one
cell = wb1.getSheetAt(0).getRow(1).getCell(2); cell = wb1.getSheetAt(0).getRow(1).getCell(2);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(12.30, cell.getNumericCellValue(), 0.0001); assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
// Re-check ref one // Re-check ref one
cell = wb1.getSheetAt(0).getRow(1).getCell(4); cell = wb1.getSheetAt(0).getRow(1).getCell(4);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(36.90, cell.getNumericCellValue(), 0.0001); assertEquals(36.90, cell.getNumericCellValue(), 0.0001);

View File

@ -199,7 +199,7 @@ public class TestWorkbookEvaluator {
} catch (RuntimeException e) { } catch (RuntimeException e) {
fail("Missing arg result not being handled correctly."); fail("Missing arg result not being handled correctly.");
} }
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cv.getCellType());
// adding blank to 1.0 gives 1.0 // adding blank to 1.0 gives 1.0
assertEquals(1.0, cv.getNumberValue(), 0.0); assertEquals(1.0, cv.getNumberValue(), 0.0);
@ -207,7 +207,7 @@ public class TestWorkbookEvaluator {
cell.setCellFormula("\"abc\"&IF(1,,)"); cell.setCellFormula("\"abc\"&IF(1,,)");
fe.notifySetFormula(cell); fe.notifySetFormula(cell);
cv = fe.evaluate(cell); cv = fe.evaluate(cell);
assertEquals(CellType.STRING, cv.getCellTypeEnum()); assertEquals(CellType.STRING, cv.getCellType());
// adding blank to "abc" gives "abc" // adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue()); assertEquals("abc", cv.getStringValue());
@ -215,7 +215,7 @@ public class TestWorkbookEvaluator {
cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)"); cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)");
fe.notifySetFormula(cell); fe.notifySetFormula(cell);
cv = fe.evaluate(cell); cv = fe.evaluate(cell);
assertEquals(CellType.STRING, cv.getCellTypeEnum()); assertEquals(CellType.STRING, cv.getCellType());
// adding blank to "abc" gives "abc" // adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue()); assertEquals("abc", cv.getStringValue());
} }
@ -240,14 +240,14 @@ public class TestWorkbookEvaluator {
} }
throw new RuntimeException(e); throw new RuntimeException(e);
} }
assertEquals(CellType.ERROR, cv.getCellTypeEnum()); assertEquals(CellType.ERROR, cv.getCellType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv.getErrorValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv.getErrorValue());
// verify circular refs are still detected properly // verify circular refs are still detected properly
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
cell.setCellFormula("OFFSET(A1,0,0)"); cell.setCellFormula("OFFSET(A1,0,0)");
cv = fe.evaluate(cell); cv = fe.evaluate(cell);
assertEquals(CellType.ERROR, cv.getCellTypeEnum()); assertEquals(CellType.ERROR, cv.getCellType());
assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue()); assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue());
} finally { } finally {
wb.close(); wb.close();
@ -387,10 +387,10 @@ public class TestWorkbookEvaluator {
CellValue result = eval.evaluate(D1); CellValue result = eval.evaluate(D1);
// Call should not modify the contents // Call should not modify the contents
assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(CellType.FORMULA, D1.getCellType());
assertEquals(expectedFormula, D1.getCellFormula()); assertEquals(expectedFormula, D1.getCellFormula());
assertEquals(CellType.NUMERIC, result.getCellTypeEnum()); assertEquals(CellType.NUMERIC, result.getCellType());
assertEquals(expectedResult, result.getNumberValue(), EPSILON); assertEquals(expectedResult, result.getNumberValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb); testIFEqualsFormulaEvaluation_teardown(wb);
@ -536,10 +536,10 @@ public class TestWorkbookEvaluator {
CellType resultCellType = eval.evaluateFormulaCellEnum(D1); CellType resultCellType = eval.evaluateFormulaCellEnum(D1);
// Call should modify the contents, but leave the formula intact // Call should modify the contents, but leave the formula intact
assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(CellType.FORMULA, D1.getCellType());
assertEquals(expectedFormula, D1.getCellFormula()); assertEquals(expectedFormula, D1.getCellFormula());
assertEquals(CellType.NUMERIC, resultCellType); assertEquals(CellType.NUMERIC, resultCellType);
assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType());
assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb); testIFEqualsFormulaEvaluation_teardown(wb);
@ -561,7 +561,7 @@ public class TestWorkbookEvaluator {
} catch (final IllegalStateException expected) { } catch (final IllegalStateException expected) {
// expected here // expected here
} }
assertEquals(CellType.NUMERIC, D1.getCellTypeEnum()); assertEquals(CellType.NUMERIC, D1.getCellType());
assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb); testIFEqualsFormulaEvaluation_teardown(wb);
@ -576,10 +576,10 @@ public class TestWorkbookEvaluator {
eval.evaluateAll(); eval.evaluateAll();
// Call should modify the contents // Call should modify the contents
assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(CellType.FORMULA, D1.getCellType());
assertEquals(expectedFormula, D1.getCellFormula()); assertEquals(expectedFormula, D1.getCellFormula());
assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType());
assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb); testIFEqualsFormulaEvaluation_teardown(wb);
@ -593,11 +593,11 @@ public class TestWorkbookEvaluator {
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
// Call should modify the contents // Call should modify the contents
assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(CellType.FORMULA, D1.getCellType());
// whitespace gets deleted because formula is parsed and re-rendered // whitespace gets deleted because formula is parsed and re-rendered
assertEquals(expectedFormula, D1.getCellFormula()); assertEquals(expectedFormula, D1.getCellFormula());
assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType());
assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb); testIFEqualsFormulaEvaluation_teardown(wb);

View File

@ -131,7 +131,7 @@ public class TestRandBetween extends TestCase {
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCellEnum(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
@ -141,7 +141,7 @@ public class TestRandBetween extends TestCase {
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCellEnum(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
// Check case where both inputs are of wrong type // Check case where both inputs are of wrong type
@ -150,7 +150,7 @@ public class TestRandBetween extends TestCase {
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCellEnum(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
} }
@ -166,14 +166,14 @@ public class TestRandBetween extends TestCase {
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCellEnum(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
bottomValueCell.setCellValue(1); bottomValueCell.setCellValue(1);
topValueCell.setCellType(CellType.BLANK); topValueCell.setCellType(CellType.BLANK);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCellEnum(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
} }

View File

@ -505,9 +505,9 @@ public final class TestCountFuncs extends TestCase {
for (int rowIx=7; rowIx<=12; rowIx++) { for (int rowIx=7; rowIx<=12; rowIx++) {
HSSFRow row = sheet1.getRow(rowIx-1); HSSFRow row = sheet1.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(CellType.FORMULA, cellA.getCellTypeEnum()); assertEquals(CellType.FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(CellType.NUMERIC, cellC.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA); CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue(); double actualValue = cv.getNumberValue();
@ -523,9 +523,9 @@ public final class TestCountFuncs extends TestCase {
for (int rowIx=9; rowIx<=14; rowIx++) { for (int rowIx=9; rowIx<=14; rowIx++) {
HSSFRow row = sheet2.getRow(rowIx-1); HSSFRow row = sheet2.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(CellType.FORMULA, cellA.getCellTypeEnum()); assertEquals(CellType.FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(CellType.NUMERIC, cellC.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA); CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue(); double actualValue = cv.getNumberValue();

View File

@ -47,13 +47,13 @@ public final class TestIsBlank extends TestCase {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue result = fe.evaluate(cell); CellValue result = fe.evaluate(cell);
assertEquals(CellType.BOOLEAN, result.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue()); assertEquals(true, result.getBooleanValue());
cell.setCellFormula("isblank(D7:D7)"); cell.setCellFormula("isblank(D7:D7)");
result = fe.evaluate(cell); result = fe.evaluate(cell);
assertEquals(CellType.BOOLEAN, result.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue()); assertEquals(true, result.getBooleanValue());
} }
} }

View File

@ -58,12 +58,12 @@ public final class TestNper {
cell.setCellFormula("NPER(12,4500,100000,100000)"); cell.setCellFormula("NPER(12,4500,100000,100000)");
cell.setCellValue(15.0); cell.setCellValue(15.0);
assertEquals("NPER(12,4500,100000,100000)", cell.getCellFormula()); assertEquals("NPER(12,4500,100000,100000)", cell.getCellFormula());
assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(15.0, cell.getNumericCellValue(), 0.0); assertEquals(15.0, cell.getNumericCellValue(), 0.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.evaluateFormulaCellEnum(cell); fe.evaluateFormulaCell(cell);
assertEquals(CellType.ERROR, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, cell.getCachedFormulaResultType());
assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue()); assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue());
wb.close(); wb.close();
} }

View File

@ -973,7 +973,7 @@ public abstract class BaseTestBugzillaIssues {
assertEquals(1, cArray.length);*/ assertEquals(1, cArray.length);*/
Cell cell = row.getCell(0); Cell cell = row.getCell(0);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
} }
{ // overwrite the row { // overwrite the row
@ -1151,18 +1151,18 @@ public abstract class BaseTestBugzillaIssues {
cfs.setCellFormula("B1"); cfs.setCellFormula("B1");
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellTypeEnum()); assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellType());
assertEquals(CellType.STRING, fe.evaluate(cfs).getCellTypeEnum()); assertEquals(CellType.STRING, fe.evaluate(cfs).getCellType());
fe.evaluateFormulaCellEnum(cfn); fe.evaluateFormulaCellEnum(cfn);
fe.evaluateFormulaCellEnum(cfs); fe.evaluateFormulaCellEnum(cfs);
// Now test // Now test
assertEquals(CellType.NUMERIC, cn.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cn.getCellType());
assertEquals(CellType.STRING, cs.getCellTypeEnum()); assertEquals(CellType.STRING, cs.getCellType());
assertEquals(CellType.FORMULA, cfn.getCellTypeEnum()); assertEquals(CellType.FORMULA, cfn.getCellType());
assertEquals(CellType.NUMERIC, cfn.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, cfn.getCachedFormulaResultType());
assertEquals(CellType.FORMULA, cfs.getCellTypeEnum()); assertEquals(CellType.FORMULA, cfs.getCellType());
assertEquals(CellType.STRING, cfs.getCachedFormulaResultTypeEnum()); assertEquals(CellType.STRING, cfs.getCachedFormulaResultType());
// Different ways of retrieving // Different ways of retrieving
assertEquals(1.2, cn.getNumericCellValue(), 0); assertEquals(1.2, cn.getNumericCellValue(), 0);
@ -1406,7 +1406,7 @@ public abstract class BaseTestBugzillaIssues {
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
Cell cell = s.createRow(0).createCell(0); Cell cell = s.createRow(0).createCell(0);
cell.setCellValue((String)null); cell.setCellValue((String)null);
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
_testDataProvider.trackAllColumnsForAutosizing(s); _testDataProvider.trackAllColumnsForAutosizing(s);
@ -1577,8 +1577,8 @@ public abstract class BaseTestBugzillaIssues {
Cell cell = row.getCell(cellId); Cell cell = row.getCell(cellId);
System.out.println("Formula:" + cell.getCellFormula()); System.out.println("Formula:" + cell.getCellFormula());
if (CellType.FORMULA == cell.getCellTypeEnum()) { if (CellType.FORMULA == cell.getCellType()) {
CellType formulaResultType = cell.getCachedFormulaResultTypeEnum(); CellType formulaResultType = cell.getCachedFormulaResultType();
System.out.println("Formula Result Type:" + formulaResultType); System.out.println("Formula Result Type:" + formulaResultType);
} }
@ -1592,8 +1592,8 @@ public abstract class BaseTestBugzillaIssues {
cell = row.getCell(cellId); cell = row.getCell(cellId);
System.out.println("Formula:" + cell.getCellFormula()); System.out.println("Formula:" + cell.getCellFormula());
if (CellType.FORMULA == cell.getCellTypeEnum()) { if (CellType.FORMULA == cell.getCellType()) {
CellType formulaResultType = cell.getCachedFormulaResultTypeEnum(); CellType formulaResultType = cell.getCachedFormulaResultType();
System.out.println("Formula Result Type:" + formulaResultType); System.out.println("Formula Result Type:" + formulaResultType);
} }
@ -1658,9 +1658,9 @@ public abstract class BaseTestBugzillaIssues {
cell3.setCellFormula("SUM(C1:C10)"); cell3.setCellFormula("SUM(C1:C10)");
cell3.setCellValue(65); cell3.setCellValue(65);
assertEquals(CellType.FORMULA, cell1.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell1.getCellType());
assertEquals(CellType.FORMULA, cell2.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell2.getCellType());
assertEquals(CellType.FORMULA, cell3.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell3.getCellType());
assertEquals("SUM(A1:A10)", cell1.getCellFormula()); assertEquals("SUM(A1:A10)", cell1.getCellFormula());
assertEquals("SUM(B1:B10)", cell2.getCellFormula()); assertEquals("SUM(B1:B10)", cell2.getCellFormula());
@ -1690,7 +1690,7 @@ public abstract class BaseTestBugzillaIssues {
for (Cell cell : row) { for (Cell cell : row) {
String cellValue; String cellValue;
switch (cell.getCellTypeEnum()) { switch (cell.getCellType()) {
case STRING: case STRING:
cellValue = cell.getRichStringCellValue().getString(); cellValue = cell.getRichStringCellValue().getString();
break; break;

View File

@ -61,13 +61,13 @@ public abstract class BaseTestCell {
cell.setCellValue(1.2); cell.setCellValue(1.2);
assertEquals(1.2, cell.getNumericCellValue(), 0.0001); assertEquals(1.2, cell.getNumericCellValue(), 0.0001);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
CellType.FORMULA, CellType.ERROR); CellType.FORMULA, CellType.ERROR);
cell.setCellValue(false); cell.setCellValue(false);
assertEquals(false, cell.getBooleanCellValue()); assertEquals(false, cell.getBooleanCellValue());
assertEquals(CellType.BOOLEAN, cell.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, cell.getCellType());
cell.setCellValue(true); cell.setCellValue(true);
assertEquals(true, cell.getBooleanCellValue()); assertEquals(true, cell.getBooleanCellValue());
assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING,
@ -76,14 +76,14 @@ public abstract class BaseTestCell {
cell.setCellValue(factory.createRichTextString("Foo")); cell.setCellValue(factory.createRichTextString("Foo"));
assertEquals("Foo", cell.getRichStringCellValue().getString()); assertEquals("Foo", cell.getRichStringCellValue().getString());
assertEquals("Foo", cell.getStringCellValue()); assertEquals("Foo", cell.getStringCellValue());
assertEquals(CellType.STRING, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN,
CellType.FORMULA, CellType.ERROR); CellType.FORMULA, CellType.ERROR);
cell.setCellValue("345"); cell.setCellValue("345");
assertEquals("345", cell.getRichStringCellValue().getString()); assertEquals("345", cell.getRichStringCellValue().getString());
assertEquals("345", cell.getStringCellValue()); assertEquals("345", cell.getStringCellValue());
assertEquals(CellType.STRING, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN,
CellType.FORMULA, CellType.ERROR); CellType.FORMULA, CellType.ERROR);
@ -91,19 +91,19 @@ public abstract class BaseTestCell {
c.setTimeInMillis(123456789); c.setTimeInMillis(123456789);
cell.setCellValue(c.getTime()); cell.setCellValue(c.getTime());
assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime());
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
CellType.FORMULA, CellType.ERROR); CellType.FORMULA, CellType.ERROR);
cell.setCellValue(c); cell.setCellValue(c);
assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime());
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
CellType.FORMULA, CellType.ERROR); CellType.FORMULA, CellType.ERROR);
cell.setCellErrorValue(FormulaError.NA.getCode()); cell.setCellErrorValue(FormulaError.NA.getCode());
assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue());
assertEquals(CellType.ERROR, cell.getCellTypeEnum()); assertEquals(CellType.ERROR, cell.getCellType());
assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN,
CellType.FORMULA, CellType.STRING); CellType.FORMULA, CellType.STRING);
@ -142,7 +142,6 @@ public abstract class BaseTestCell {
/** /**
* test that Boolean (BoolErrRecord) are supported properly. * test that Boolean (BoolErrRecord) are supported properly.
* @see testErr
*/ */
@Test @Test
public void testBool() throws IOException { public void testBool() throws IOException {
@ -177,13 +176,13 @@ public abstract class BaseTestCell {
c = r.getCell(1); c = r.getCell(1);
assertEquals(0, c.getRowIndex()); assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex()); assertEquals(1, c.getColumnIndex());
assertEquals(CellType.BOOLEAN, c.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, c.getCellType());
assertEquals("B1 value", true, c.getBooleanCellValue()); assertEquals("B1 value", true, c.getBooleanCellValue());
c = r.getCell(2); c = r.getCell(2);
assertEquals(0, c.getRowIndex()); assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex()); assertEquals(2, c.getColumnIndex());
assertEquals(CellType.BOOLEAN, c.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, c.getCellType());
assertEquals("C1 value", false, c.getBooleanCellValue()); assertEquals("C1 value", false, c.getBooleanCellValue());
wb2.close(); wb2.close();
@ -191,7 +190,7 @@ public abstract class BaseTestCell {
/** /**
* test that Error types (BoolErrRecord) are supported properly. * test that Error types (BoolErrRecord) are supported properly.
* @see testBool * @see #testBool
*/ */
@Test @Test
public void testErr() throws IOException { public void testErr() throws IOException {
@ -227,13 +226,13 @@ public abstract class BaseTestCell {
c = r.getCell(1); c = r.getCell(1);
assertEquals(0, c.getRowIndex()); assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex()); assertEquals(1, c.getColumnIndex());
assertEquals(CellType.ERROR, c.getCellTypeEnum()); assertEquals(CellType.ERROR, c.getCellType());
assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue());
c = r.getCell(2); c = r.getCell(2);
assertEquals(0, c.getRowIndex()); assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex()); assertEquals(2, c.getColumnIndex());
assertEquals(CellType.ERROR, c.getCellTypeEnum()); assertEquals(CellType.ERROR, c.getCellType());
assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue());
wb2.close(); wb2.close();
@ -273,7 +272,7 @@ public abstract class BaseTestCell {
r = s.getRow(0); r = s.getRow(0);
c = r.getCell(0); c = r.getCell(0);
assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellTypeEnum()); assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellType());
cs = c.getCellStyle(); cs = c.getCellStyle();
assertNotNull("Formula Cell Style", cs); assertNotNull("Formula Cell Style", cs);
@ -351,25 +350,25 @@ public abstract class BaseTestCell {
Cell c1 = r.createCell(0); Cell c1 = r.createCell(0);
c1.setCellFormula("NA()"); c1.setCellFormula("NA()");
assertEquals(0.0, c1.getNumericCellValue(), 0.0); assertEquals(0.0, c1.getNumericCellValue(), 0.0);
assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType());
c1.setCellValue(10); c1.setCellValue(10);
assertEquals(10.0, c1.getNumericCellValue(), 0.0); assertEquals(10.0, c1.getNumericCellValue(), 0.0);
assertEquals(CellType.FORMULA, c1.getCellTypeEnum()); assertEquals(CellType.FORMULA, c1.getCellType());
assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType());
Cell c2 = r.createCell(1); Cell c2 = r.createCell(1);
c2.setCellFormula("NA()"); c2.setCellFormula("NA()");
assertEquals(0.0, c2.getNumericCellValue(), 0.0); assertEquals(0.0, c2.getNumericCellValue(), 0.0);
assertEquals(CellType.NUMERIC, c2.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, c2.getCachedFormulaResultType());
c2.setCellValue("I changed!"); c2.setCellValue("I changed!");
assertEquals("I changed!", c2.getStringCellValue()); assertEquals("I changed!", c2.getStringCellValue());
assertEquals(CellType.FORMULA, c2.getCellTypeEnum()); assertEquals(CellType.FORMULA, c2.getCellType());
assertEquals(CellType.STRING, c2.getCachedFormulaResultTypeEnum()); assertEquals(CellType.STRING, c2.getCachedFormulaResultType());
//calglin Cell.setCellFormula(null) for a non-formula cell //calglin Cell.setCellFormula(null) for a non-formula cell
Cell c3 = r.createCell(2); Cell c3 = r.createCell(2);
c3.setCellFormula(null); c3.setCellFormula(null);
assertEquals(CellType.BLANK, c3.getCellTypeEnum()); assertEquals(CellType.BLANK, c3.getCellType());
wb.close(); wb.close();
} }
@ -424,11 +423,11 @@ public abstract class BaseTestCell {
Cell cell = createACell(wb); Cell cell = createACell(wb);
cell.setCellValue("TRUE"); cell.setCellValue("TRUE");
assertEquals(CellType.STRING, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCellType());
// test conversion of cell from text to boolean // test conversion of cell from text to boolean
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
assertEquals(CellType.BOOLEAN, cell.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, cell.getCellType());
assertEquals(true, cell.getBooleanCellValue()); assertEquals(true, cell.getBooleanCellValue());
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
assertEquals("TRUE", cell.getRichStringCellValue().getString()); assertEquals("TRUE", cell.getRichStringCellValue().getString());
@ -436,7 +435,7 @@ public abstract class BaseTestCell {
// 'false' text to bool and back // 'false' text to bool and back
cell.setCellValue("FALSE"); cell.setCellValue("FALSE");
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
assertEquals(CellType.BOOLEAN, cell.getCellTypeEnum()); assertEquals(CellType.BOOLEAN, cell.getCellType());
assertEquals(false, cell.getBooleanCellValue()); assertEquals(false, cell.getBooleanCellValue());
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
assertEquals("FALSE", cell.getRichStringCellValue().getString()); assertEquals("FALSE", cell.getRichStringCellValue().getString());
@ -593,17 +592,17 @@ public abstract class BaseTestCell {
cell = row.createCell(0, CellType.NUMERIC); cell = row.createCell(0, CellType.NUMERIC);
cell.setCellValue(1.0); cell.setCellValue(1.0);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(1.0, cell.getNumericCellValue(), 0.0); assertEquals(1.0, cell.getNumericCellValue(), 0.0);
cell = row.createCell(1, CellType.NUMERIC); cell = row.createCell(1, CellType.NUMERIC);
cell.setCellValue(2.0); cell.setCellValue(2.0);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(2.0, cell.getNumericCellValue(), 0.0); assertEquals(2.0, cell.getNumericCellValue(), 0.0);
cell = row.createCell(2, CellType.FORMULA); cell = row.createCell(2, CellType.FORMULA);
cell.setCellFormula("SUM(A1:B1)"); cell.setCellFormula("SUM(A1:B1)");
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("SUM(A1:B1)", cell.getCellFormula()); assertEquals("SUM(A1:B1)", cell.getCellFormula());
//serialize and check again //serialize and check again
@ -611,15 +610,15 @@ public abstract class BaseTestCell {
wb1.close(); wb1.close();
row = wb2.getSheetAt(0).getRow(0); row = wb2.getSheetAt(0).getRow(0);
cell = row.getCell(0); cell = row.getCell(0);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(1.0, cell.getNumericCellValue(), 0.0); assertEquals(1.0, cell.getNumericCellValue(), 0.0);
cell = row.getCell(1); cell = row.getCell(1);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(2.0, cell.getNumericCellValue(), 0.0); assertEquals(2.0, cell.getNumericCellValue(), 0.0);
cell = row.getCell(2); cell = row.getCell(2);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("SUM(A1:B1)", cell.getCellFormula()); assertEquals("SUM(A1:B1)", cell.getCellFormula());
wb2.close(); wb2.close();
} }
@ -676,17 +675,17 @@ public abstract class BaseTestCell {
Cell cell0 = row.createCell(0); Cell cell0 = row.createCell(0);
cell0.setCellValue(Double.NaN); cell0.setCellValue(Double.NaN);
assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellTypeEnum()); assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellType());
assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue())); assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue()));
Cell cell1 = row.createCell(1); Cell cell1 = row.createCell(1);
cell1.setCellValue(Double.POSITIVE_INFINITY); cell1.setCellValue(Double.POSITIVE_INFINITY);
assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellTypeEnum()); assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellType());
assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue())); assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue()));
Cell cell2 = row.createCell(2); Cell cell2 = row.createCell(2);
cell2.setCellValue(Double.NEGATIVE_INFINITY); cell2.setCellValue(Double.NEGATIVE_INFINITY);
assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellTypeEnum()); assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellType());
assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue())); assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue()));
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
@ -694,15 +693,15 @@ public abstract class BaseTestCell {
row = wb2.getSheetAt(0).getRow(0); row = wb2.getSheetAt(0).getRow(0);
cell0 = row.getCell(0); cell0 = row.getCell(0);
assertEquals(CellType.ERROR, cell0.getCellTypeEnum()); assertEquals(CellType.ERROR, cell0.getCellType());
assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue())); assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue()));
cell1 = row.getCell(1); cell1 = row.getCell(1);
assertEquals(CellType.ERROR, cell1.getCellTypeEnum()); assertEquals(CellType.ERROR, cell1.getCellType());
assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue())); assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue()));
cell2 = row.getCell(2); cell2 = row.getCell(2);
assertEquals(CellType.ERROR, cell2.getCellTypeEnum()); assertEquals(CellType.ERROR, cell2.getCellType());
assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue())); assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue()));
wb2.close(); wb2.close();
} }
@ -903,21 +902,21 @@ public abstract class BaseTestCell {
RichTextString nullStr = null; RichTextString nullStr = null;
cell.setCellValue(nullStr); cell.setCellValue(nullStr);
assertEquals("", cell.getStringCellValue()); assertEquals("", cell.getStringCellValue());
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
cell = sheet.createRow(0).createCell(1); cell = sheet.createRow(0).createCell(1);
cell.setCellValue(1.2d); cell.setCellValue(1.2d);
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cell.getCellType());
cell.setCellValue(nullStr); cell.setCellValue(nullStr);
assertEquals("", cell.getStringCellValue()); assertEquals("", cell.getStringCellValue());
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
cell = sheet.createRow(0).createCell(1); cell = sheet.createRow(0).createCell(1);
cell.setCellValue(wb.getCreationHelper().createRichTextString("Test")); cell.setCellValue(wb.getCreationHelper().createRichTextString("Test"));
assertEquals(CellType.STRING, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCellType());
cell.setCellValue(nullStr); cell.setCellValue(nullStr);
assertEquals("", cell.getStringCellValue()); assertEquals("", cell.getStringCellValue());
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
wb.close(); wb.close();
} }
@ -1015,38 +1014,4 @@ public abstract class BaseTestCell {
wb.close(); wb.close();
} }
@Test
public void primitiveToEnumReplacementDoesNotBreakBackwardsCompatibility() throws IOException {
// bug 59836
// until we have changes POI from working on primitives (int) to enums,
// we should make sure we minimize backwards compatibility breakages.
// This method tests the old way of working with cell types, alignment, etc.
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
// Cell.CELL_TYPE_* -> CellType.*
cell.setCellValue(5.0);
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
assertEquals(0, cell.getCellType()); //make sure that hard-coded int literals still work, even though users should be using the named constants
assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); // make sure old way and new way are compatible
// make sure switch(int|Enum) still works. Cases must be statically resolvable in Java 6 ("constant expression required")
switch(cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
// expected
break;
case Cell.CELL_TYPE_STRING:
case Cell.CELL_TYPE_BOOLEAN:
case Cell.CELL_TYPE_ERROR:
case Cell.CELL_TYPE_FORMULA:
case Cell.CELL_TYPE_BLANK:
default:
fail("unexpected cell type: " + cell.getCellType());
}
wb.close();
}
} }