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

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

Introduction

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

Prototype

boolean getBooleanCellValue();

Source Link

Document

Get the value of the cell as a boolean.

Usage

From source file:it.redev.parco.utils.ExcelUtils.java

License:Open Source License

public static String getCellValue(Cell cell) {
    String value = null;/*from   w  ww . j  a  va  2  s .  c  o  m*/
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN:
        value = new Boolean(cell.getBooleanCellValue()).toString();
        break;
    case Cell.CELL_TYPE_NUMERIC:
        value = new BigDecimal(cell.getNumericCellValue()).toPlainString();
        break;
    case Cell.CELL_TYPE_STRING:
        value = cell.getStringCellValue();
        break;
    }
    return value;
}

From source file:jasco.Jasco.java

private List<List<String>> convertSheetToArrayList(int y, int height, int x, int width, Sheet sheet1) {
    List<List<String>> rows = new ArrayList<>();
    for (int row = y; row < y + height; row++) {
        ArrayList<String> rowData = new ArrayList<>();
        for (int col = x; col < x + width; col++) {
            Cell cell = sheet1.getRow(row).getCell(col);
            switch (cell.getCellType()) {
            case (Cell.CELL_TYPE_STRING):
                RichTextString str = cell.getRichStringCellValue();
                rowData.add(str.toString());
                break;
            case (Cell.CELL_TYPE_NUMERIC):
                rowData.add("" + cell.getNumericCellValue());
                break;
            case (Cell.CELL_TYPE_BOOLEAN):
                rowData.add("" + cell.getBooleanCellValue());
                break;
            case (Cell.CELL_TYPE_FORMULA):
                switch (cell.getCachedFormulaResultType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    rowData.add("" + cell.getNumericCellValue());
                    break;
                case Cell.CELL_TYPE_STRING:
                    rowData.add("" + cell.getRichStringCellValue());
                    break;
                }//from  w  w w .j  a  v  a2  s .  c o  m
                break;
            case (Cell.CELL_TYPE_BLANK):
                rowData.add("");
                break;
            default:
                System.out.println("unknown cell type" + cell.getCellType());
            }

            rows.add(rowData);
        }
    }
    return rows;
}

From source file:javacommon.excel.ExcelReader.java

/**
 * ???/*from www .j  a  v  a 2 s  .c  o  m*/
 *
 * @param c ?
 * @return
 */
private String getCellStringValue(Cell c) {
    if (c == null) {
        return "";
    }
    String value = null;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMaximumFractionDigits(12);
    switch (c.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN:
        value = String.valueOf(c.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(c)) {
            return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue());
        } else if ("@".equals(c.getCellStyle().getDataFormatString())) {
            value = nf.format(c.getNumericCellValue());
        } else if ("General".equals(c.getCellStyle().getDataFormatString())) {
            value = nf.format(c.getNumericCellValue());
        } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) {
            value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()),
                    c.getCellStyle().getDataFormatString());
        } else {
            value = nf.format(c.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_STRING:
        value = c.getStringCellValue();
        break;
    case Cell.CELL_TYPE_FORMULA:
        value = c.getCellFormula();
        break;
    }
    return value == null ? "" : value.trim();
}

From source file:javacommon.excel.ExcelReader.java

/**
 * ???/*from   ww w. j  a  v a 2  s. c o m*/
 *
 * @param c ?
 * @return
 */
private String getCellStringFormatValue(Cell c) {
    if (c == null) {
        return "";
    }
    String value = null;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMaximumFractionDigits(12);
    switch (c.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN:
        value = String.valueOf(c.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(c)) {
            return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue());
        } else if ("@".equals(c.getCellStyle().getDataFormatString())) {
            value = nf.format(c.getNumericCellValue());
        } else if ("General".equals(c.getCellStyle().getDataFormatString())) {
            value = nf.format(c.getNumericCellValue());
        } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) {
            value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()),
                    c.getCellStyle().getDataFormatString());
        } else {
            value = nf.format(c.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_STRING:
        value = c.getStringCellValue();
        break;
    case Cell.CELL_TYPE_FORMULA:
        return c.getCellFormula();
    }
    return value == null ? "" : value.trim();
}

From source file:javacommon.excel.ExcelReader.java

/**
 * ???//from   w  ww  .ja v a  2s  .  com
 *
 * @param c ?
 * @return
 */
private Object getCellValue(Cell c) {
    if (c == null) {
        return null;
    }
    switch (c.getCellType()) {
    case Cell.CELL_TYPE_BLANK:
        return null;
    case Cell.CELL_TYPE_BOOLEAN:
        return c.getBooleanCellValue();
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(c)) {
            return c.getDateCellValue();
        }
        return c.getNumericCellValue();
    case Cell.CELL_TYPE_STRING:
        return c.getStringCellValue();
    case Cell.CELL_TYPE_FORMULA:
        return c.getCellFormula();
    }
    return null;
}

From source file:jexcel4py.Jexcel4py.java

private void copyCell(Cell rdCell, Cell wrCell) {
    //        wrCell.setCellStyle(rdCell.getCellStyle());
    //        wrCell.setCellType(rdCell.getCellType());
    int cellStyle = rdCell.getCellType();
    String rdCellValue = rdCell.getStringCellValue();

    switch (cellStyle) {
    case Cell.CELL_TYPE_BLANK:
        wrCell.setCellValue("heys");
        break;/*  www.  ja v  a 2  s  . c  o m*/
    case Cell.CELL_TYPE_BOOLEAN:
        wrCell.setCellValue(rdCell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_ERROR:
        wrCell.setCellValue(rdCell.getErrorCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        wrCell.setCellValue(rdCell.getCellFormula());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        wrCell.setCellValue(rdCell.getNumericCellValue());
        break;
    case Cell.CELL_TYPE_STRING:
        wrCell.setCellValue(rdCell.getStringCellValue());
        break;

    default:
        wrCell.setCellValue("heys");
        break;
    }
}

From source file:joinery.impl.Serialization.java

License:Open Source License

private static final Object readCell(final Cell cell) {
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(cell)) {
            return DateUtil.getJavaDate(cell.getNumericCellValue());
        }/* www.jav  a  2  s  . c  o  m*/
        return cell.getNumericCellValue();
    case Cell.CELL_TYPE_BOOLEAN:
        return cell.getBooleanCellValue();
    default:
        return cell.getStringCellValue();
    }
}

From source file:jp.qpg.Tool.java

License:Apache License

/**
 * get cell value/* w w  w . jav a  2s  .c  o m*/
 * 
 * @param cell cell
 * @return cell value
 */
public static Optional<String> cellValue(Cell cell) {
    String text = null;
    try {
        text = formatter.formatAsString(cell, Locale.JAPAN);
    } catch (IllegalStateException e) {
        switch (cell.getCellType()) {

        case BOOLEAN:
            text = String.valueOf(cell.getBooleanCellValue());
            break;
        case STRING:
            text = cell.getStringCellValue();
            break;
        case NUMERIC:
            text = String.valueOf(cell.getNumericCellValue());
            break;
        case ERROR:
            text = String.valueOf(cell.getErrorCellValue());
            break;
        case BLANK:
            break;
        case FORMULA:
            break;
        case _NONE:
            break;
        }
    }
    return Optional.ofNullable(text).filter(((Predicate<String>) String::isEmpty).negate());
}

From source file:jp.ryoyamamoto.poiutils.Cells.java

License:Apache License

private static void copyCellValue(Cell source, Cell target) {
    switch (source.getCellType()) {
    case Cell.CELL_TYPE_NUMERIC:
        target.setCellValue(source.getNumericCellValue());
        break;/*from w w w  . jav  a2 s .c  o m*/
    case Cell.CELL_TYPE_STRING:
        target.setCellValue(source.getRichStringCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        target.setCellFormula(source.getCellFormula());
        break;
    case Cell.CELL_TYPE_BLANK:
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        target.setCellValue(source.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_ERROR:
        target.setCellErrorValue(source.getErrorCellValue());
        break;
    }
}

From source file:jschsftp.JSCHsftp.java

private static String getCellValue(Cell cell) {

    String strCellValue = "";
    if (cell == null)
        return "";
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        strCellValue = cell.getStringCellValue();
        break;/* w  ww.j a va2 s .co  m*/
    case Cell.CELL_TYPE_NUMERIC:
        strCellValue = "" + cell.getNumericCellValue();
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        strCellValue = "" + cell.getBooleanCellValue();
        break;
    default:
        break;
    }
    return strCellValue;
}