Example usage for org.apache.poi.ss.usermodel Cell getErrorCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getErrorCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getErrorCellValue.

Prototype

byte getErrorCellValue();

Source Link

Document

Get the value of the cell as an error code.

Usage

From source file:com.canoo.webtest.plugins.exceltest.ExcelCellUtils.java

License:Open Source License

public static String getCellValueAt(final Cell cell) {
    if (null == cell) {
        return "";
    }//from   w w w . j  a v a2s .c o  m
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        return cell.getRichStringCellValue().getString();
    case Cell.CELL_TYPE_NUMERIC:
        return asStringTrimInts(cell.getNumericCellValue());
    case Cell.CELL_TYPE_BLANK:
        return "";
    case Cell.CELL_TYPE_BOOLEAN:
        return String.valueOf(cell.getBooleanCellValue());
    case Cell.CELL_TYPE_FORMULA:
        return cell.getCellFormula();
    case Cell.CELL_TYPE_ERROR:
        return "Error Code " + String.valueOf(cell.getErrorCellValue() & 0xFF);
    ///CLOVER:OFF there are currently no other types.  Potentially more in future?
    default:
        LOG.warn("Cell Type not supported: " + cell.getCellType());
        return "";
    ///CLOVER:ON
    }
}

From source file:com.cloudera.sa.ExcelRecordReader.java

License:Apache License

private Text getCellValue(Cell cell) {
    Text out = new Text();
    CellType cellType = cell.getCellTypeEnum();

    if (cellType == CellType.STRING) {
        out.set(cell.getStringCellValue());
    } else if (cellType == CellType.NUMERIC) {
        out.set(String.valueOf(cell.getNumericCellValue()));
    } else if (cellType == CellType.FORMULA) {
        out.set(cell.getCellFormula());/*from w  ww.  j  a va 2  s.  c  om*/
    } else if (cellType == CellType.ERROR) {
        out.set(String.valueOf(cell.getErrorCellValue()));
    } else if (cellType == CellType.BOOLEAN) {
        out.set(String.valueOf(cell.getBooleanCellValue()));
    } else {
        out.set("");
    }

    return out;
}

From source file:com.dataart.spreadsheetanalytics.engine.ConverterUtils.java

License:Apache License

/** Returns the new {@link CellValue} from provided {@link Cell}. */
public static ICellValue resolveCellValue(Cell c) {
    if (c == null) {
        return CellValue.BLANK;
    }//  w  ww  .  jav  a2  s. com

    switch (c.getCellType()) {
    case CELL_TYPE_NUMERIC: {
        return CellValue.from(c.getNumericCellValue());
    }
    case CELL_TYPE_STRING: {
        return CellValue.from(c.getStringCellValue());
    }
    case CELL_TYPE_BOOLEAN: {
        return CellValue.from(c.getBooleanCellValue());
    }
    case CELL_TYPE_ERROR: {
        return CellValue.from(forInt(c.getErrorCellValue()).getString());
    }
    case CELL_TYPE_BLANK: {
        return CellValue.BLANK;
    }
    case CELL_TYPE_FORMULA: {
        return CellValue.from(String.format("%s%s", FORMULA_PREFIX, c.getCellFormula()));
    }
    default: {
        throw new CalculationEngineException(
                String.format("Cell's type %s is not supported.", c.getCellType()));
    }
    }
}

From source file:com.dituiba.excel.ExcelUtility.java

License:Apache License

public static void copyCell(Cell srcCell, Cell distCell) {
    distCell.setCellStyle(srcCell.getCellStyle());
    if (srcCell.getCellComment() != null) {
        distCell.setCellComment(srcCell.getCellComment());
    }//w  w  w  .  j  ava2  s  .c  o  m
    int srcCellType = srcCell.getCellType();
    distCell.setCellType(srcCellType);

    if (srcCellType == Cell.CELL_TYPE_NUMERIC) {
        if (DateUtil.isCellDateFormatted(srcCell)) {
            distCell.setCellValue(srcCell.getDateCellValue());
        } else {
            distCell.setCellValue(srcCell.getNumericCellValue());
        }
    } else if (srcCellType == Cell.CELL_TYPE_STRING) {
        distCell.setCellValue(srcCell.getRichStringCellValue());
    } else if (srcCellType == Cell.CELL_TYPE_BLANK) {
        //nothing
    } else if (srcCellType == Cell.CELL_TYPE_BOOLEAN) {
        distCell.setCellValue(srcCell.getBooleanCellValue());
    } else if (srcCellType == Cell.CELL_TYPE_ERROR) {
        distCell.setCellErrorValue(srcCell.getErrorCellValue());
    } else if (srcCellType == Cell.CELL_TYPE_FORMULA) {
        distCell.setCellFormula(srcCell.getCellFormula());
    } else {
        //nothing
    }
}

From source file:com.funtl.framework.smoke.core.commons.excel.ImportExcel.java

License:Apache License

/**
 * ??/*ww  w  . j av a2s.c o m*/
 *
 * @param row    ?
 * @param column ???
 * @return ?
 */
@SuppressWarnings("deprecation")
public Object getCellValue(Row row, int column) {
    Object val = "";
    try {
        Cell cell = row.getCell(column);
        if (cell != null) {
            if (cell.getCellTypeEnum() == CellType.NUMERIC) {
                val = cell.getNumericCellValue();
            } else if (cell.getCellTypeEnum() == CellType.STRING) {
                val = cell.getStringCellValue();
            } else if (cell.getCellTypeEnum() == CellType.FORMULA) {
                val = cell.getCellFormula();
            } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) {
                val = cell.getBooleanCellValue();
            } else if (cell.getCellTypeEnum() == CellType.ERROR) {
                val = cell.getErrorCellValue();
            }
        }
    } catch (Exception e) {
        return val;
    }
    return val;
}

From source file:com.github.camaral.sheeco.exceptions.SpreadsheetViolation.java

License:Apache License

private static Object getCellValue(final Cell cell) {
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(cell)) {
            return cell.getDateCellValue();
        }//from  w w  w  .j  a  v a  2s .c o  m
        return cell.getNumericCellValue();
    case Cell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
    case Cell.CELL_TYPE_BLANK:
        return null;
    case Cell.CELL_TYPE_BOOLEAN:
        return cell.getBooleanCellValue();
    case Cell.CELL_TYPE_ERROR:
        return cell.getErrorCellValue();
    case Cell.CELL_TYPE_FORMULA:
        return cell.getCellFormula();
    default:
        throw new UnsupportedOperationException("CellType " + cell.getCellType() + " is invalid");
    }
}

From source file:com.heimaide.server.common.utils.excel.ImportExcel.java

License:Open Source License

/**
 * ??/*  w  w w.ja v a2  s  .  co m*/
 * @param row ?
 * @param column ???
 * @return ?
 */
public Object getCellValue(Row row, int column) {
    Object val = "";
    try {
        Cell cell = row.getCell(column);
        if (cell != null) {
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                val = cell.getNumericCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                val = cell.getStringCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                try {
                    if (HSSFDateUtil.isCellDateFormatted(cell)) {
                        val = cell.getDateCellValue();
                    } else {
                        val = String.valueOf(cell.getNumericCellValue());
                    }
                } catch (IllegalStateException e) {
                    val = String.valueOf(cell.getRichStringCellValue());
                }
            } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                val = cell.getBooleanCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
                val = cell.getErrorCellValue();
            }
        }
    } catch (Exception e) {
        return val;
    }
    return val;
}

From source file:com.jmc.jfxxlsdiff.util.POIXlsUtil.java

public static Object getCellValue(Cell cell) {
    Object cv = null;/*from  w  w w  .j a v a  2  s.co  m*/

    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_BLANK: {
        break;
    }
    case Cell.CELL_TYPE_BOOLEAN: {
        cv = cell.getBooleanCellValue();
        break;
    }
    case Cell.CELL_TYPE_ERROR: {
        cv = cell.getErrorCellValue();
        break;
    }
    case Cell.CELL_TYPE_FORMULA: {
        cv = getFormulaValue(cell);
        break;
    }
    case Cell.CELL_TYPE_NUMERIC: {
        if (DateUtil.isCellDateFormatted(cell)) {
            // format in form of M/D/YY
            //Calendar cal = Calendar.getInstance();
            //cal.setTime( DateUtil.getJavaDate( d ) );
            //cv = cal.getTime();
            cv = cell.getDateCellValue();
        } else {
            cv = cell.getNumericCellValue();
        }
        break;
    }
    case Cell.CELL_TYPE_STRING: {
        cv = cell.getStringCellValue();
        break;
    }
    default: {
        logger.log(Level.WARNING, "Unexpected cell type = {0}", cell.getCellType());
        break;
    }
    }

    return cv;
}

From source file:com.kybelksties.excel.ExcelSheetTableModel.java

License:Open Source License

/**
 * Get the value contained in the cell.// ww w.  ja  v  a 2  s  . c  o m
 *
 * @param cell the examined cell
 * @return the value as Boolean, Numeric, String, Blank, Error or Formula
 */
public static Object getCellValue(Cell cell) {
    return cell == null ? ""
            : cell.getCellType() == Cell.CELL_TYPE_BOOLEAN ? cell.getBooleanCellValue()
                    : cell.getCellType() == Cell.CELL_TYPE_NUMERIC
                            ? (DateUtil.isCellDateFormatted(cell) ? cell.getDateCellValue()
                                    : cell.getNumericCellValue())
                            : cell.getCellType() == Cell.CELL_TYPE_STRING ? cell.getStringCellValue()
                                    : cell.getCellType() == Cell.CELL_TYPE_BLANK ? cell.getStringCellValue()
                                            : cell.getCellType() == Cell.CELL_TYPE_ERROR
                                                    ? cell.getErrorCellValue()
                                                    : cell.getCellType() == Cell.CELL_TYPE_FORMULA
                                                            ? cell.getCachedFormulaResultType()
                                                            : cell.getStringCellValue();
}

From source file:com.kybelksties.excel.ExcelSheetTableModel.java

License:Open Source License

/**
 * Retrieve the cell value as String./*from  www. j ava 2  s. co m*/
 *
 * @param rowIndex row-number of the cell
 * @param colIndex column-number of the cell
 * @return the converted cell-value and trimmed cell value if exists, empty
 *         string else
 */
public String getCellValueAsString(int rowIndex, int colIndex) {
    DataFormatter formatter = new DataFormatter();
    FormulaEvaluator eval = workbook.getCreationHelper().createFormulaEvaluator();
    String value;
    Cell cell = getCellAt(rowIndex, colIndex);
    if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_ERROR) {
            value = ErrorConstants.getText(cell.getErrorCellValue());
        } else {
            value = formatter.formatCellValue(cell, eval);
        }
    } else {
        value = formatter.formatCellValue(cell);
    }
    return value.trim();
}