Example usage for org.apache.poi.ss.usermodel CellType BOOLEAN

List of usage examples for org.apache.poi.ss.usermodel CellType BOOLEAN

Introduction

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

Prototype

CellType BOOLEAN

To view the source code for org.apache.poi.ss.usermodel CellType BOOLEAN.

Click Source Link

Document

Boolean cell type

Usage

From source file:cn.edu.zjnu.acm.judge.util.excel.ExcelUtil.java

License:Apache License

private static void create(Stream<?> stream, Row row) {
    AtomicInteger counter = new AtomicInteger();
    stream.forEach(value -> {//from   www . j a  v a2  s  . co m
        if (value != null) {
            if (value instanceof String) {
                row.createCell(counter.getAndIncrement(), CellType.STRING).setCellValue((String) value);
            } else if (value instanceof Number) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC)
                        .setCellValue(((Number) value).doubleValue());
            } else if (value instanceof Boolean) {
                row.createCell(counter.getAndIncrement(), CellType.BOOLEAN).setCellValue((Boolean) value);
            } else if (value instanceof Date) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Date) value);
            } else if (value instanceof Calendar) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Calendar) value);
            } else {
                row.createCell(counter.getAndIncrement(), CellType.ERROR);
            }
        } else {
            row.createCell(counter.getAndIncrement(), CellType.BLANK);
        }
    });
}

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());/*w ww . j a  v  a 2s  .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.funtl.framework.smoke.core.commons.excel.ImportExcel.java

License:Apache License

/**
 * ??/*from   w  w  w.j a v  a 2 s .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:de.jlo.talendcomp.excel.SpreadsheetInput.java

License:Apache License

private String getStringCellValue(Cell cell, int originalColumnIndex) throws Exception {
    String value = null;/*from   www  . j  av  a  2 s.co  m*/
    if (cell != null) {
        CellType cellType = cell.getCellTypeEnum();
        if (cellType == CellType.FORMULA) {
            try {
                value = getDataFormatter().formatCellValue(cell, getFormulaEvaluator());
            } catch (Exception e) {
                if (useCachedValuesForFailedEvaluations) {
                    cellType = cell.getCachedFormulaResultTypeEnum();
                    if (cellType == CellType.STRING) {
                        if (returnURLInsteadOfName) {
                            Hyperlink link = cell.getHyperlink();
                            if (link != null) {
                                if (concatenateLabelUrl) {
                                    String url = link.getAddress();
                                    if (url == null) {
                                        url = "";
                                    }
                                    String label = link.getLabel();
                                    if (label == null) {
                                        label = "";
                                    }
                                    value = label + "|" + url;
                                } else {
                                    value = link.getAddress();
                                }
                            } else {
                                value = cell.getStringCellValue();
                            }
                        } else {
                            value = cell.getStringCellValue();
                        }
                    } else if (cellType == CellType.NUMERIC) {
                        if (DateUtil.isCellDateFormatted(cell)) {
                            if (defaultDateFormat != null) {
                                Date d = cell.getDateCellValue();
                                if (d != null) {
                                    value = defaultDateFormat.format(d);
                                }
                            } else {
                                value = getDataFormatter().formatCellValue(cell);
                            }
                        } else {
                            if (overrideExcelNumberFormat) {
                                value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue());
                            } else {
                                value = getDataFormatter().formatCellValue(cell);
                            }
                        }
                    } else if (cellType == CellType.BOOLEAN) {
                        value = cell.getBooleanCellValue() ? "true" : "false";
                    }
                } else {
                    throw e;
                }
            }
        } else if (cellType == CellType.STRING) {
            if (returnURLInsteadOfName) {
                Hyperlink link = cell.getHyperlink();
                if (link != null) {
                    if (concatenateLabelUrl) {
                        String url = link.getAddress();
                        if (url == null) {
                            url = "";
                        }
                        String label = link.getLabel();
                        if (label == null) {
                            label = "";
                        }
                        value = label + "|" + url;
                    } else {
                        value = link.getAddress();
                    }
                } else {
                    value = cell.getStringCellValue();
                }
            } else {
                value = cell.getStringCellValue();
            }
        } else if (cellType == CellType.NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                value = getDataFormatter().formatCellValue(cell);
            } else {
                if (overrideExcelNumberFormat) {
                    value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue());
                } else {
                    value = getDataFormatter().formatCellValue(cell);
                }
            }
        } else if (cellType == CellType.BOOLEAN) {
            value = cell.getBooleanCellValue() ? "true" : "false";
        } else if (cellType == CellType.BLANK) {
            value = null;
        }
    }
    return value;
}

From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java

License:Apache License

private Boolean getBooleanCellValue(Cell cell) throws Exception {
    Boolean value = null;/*from   w w  w .j  ava2 s.c  o m*/
    if (cell != null) {
        CellType cellType = cell.getCellTypeEnum();
        if (cellType == CellType.FORMULA) {
            try {
                String s = getDataFormatter().formatCellValue(cell, getFormulaEvaluator());
                value = toBool(s);
            } catch (Exception e) {
                if (useCachedValuesForFailedEvaluations) {
                    cellType = cell.getCachedFormulaResultTypeEnum();
                    if (cellType == CellType.STRING) {
                        String s = cell.getStringCellValue();
                        value = toBool(s);
                    } else if (cellType == CellType.NUMERIC) {
                        double s = cell.getNumericCellValue();
                        value = toBool(s);
                    } else if (cellType == CellType.BOOLEAN) {
                        value = cell.getBooleanCellValue();
                    }
                }
            }
        } else if (cellType == CellType.STRING) {
            String s = cell.getStringCellValue();
            value = toBool(s);
        } else if (cellType == CellType.NUMERIC) {
            double s = cell.getNumericCellValue();
            value = toBool(s);
        } else if (cellType == CellType.BOOLEAN) {
            value = cell.getBooleanCellValue();
        }
    }
    return value;
}

From source file:de.jlo.talendcomp.excel.SpreadsheetNamedCellInput.java

License:Apache License

public Object getCellValue() {
    if (currentNamedCell != null) { // cell.getCellTypeEnum() == CellType.BLANK
        if (currentNamedCell.getCellTypeEnum() == CellType.BLANK) {
            valueClass = null;/*w w  w . ja  v  a  2  s  .c o m*/
            return null;
        } else if (currentNamedCell.getCellTypeEnum() == CellType.BOOLEAN) {
            valueClass = "java.lang.Boolean";
            return currentNamedCell.getBooleanCellValue();
        } else if (currentNamedCell.getCellTypeEnum() == CellType.ERROR) {
            valueClass = null;
            return null;
        } else if (currentNamedCell.getCellTypeEnum() == CellType.FORMULA) {
            valueClass = "java.lang.String";
            return getDataFormatter().formatCellValue(currentNamedCell, getFormulaEvaluator());
        } else if (currentNamedCell.getCellTypeEnum() == CellType.NUMERIC) {
            if (DateUtil.isCellDateFormatted(currentNamedCell)) {
                valueClass = "java.util.Date";
                return currentNamedCell.getDateCellValue();
            } else {
                valueClass = "java.lang.Double";
                return currentNamedCell.getNumericCellValue();
            }
        } else if (currentNamedCell.getCellTypeEnum() == CellType.STRING) {
            valueClass = "java.lang.String";
            return currentNamedCell.getStringCellValue();
        } else {
            valueClass = null;
            return null;
        }
    } else {
        valueClass = null;
        return null;
    }
}

From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java

License:Apache License

private void writeCellValue(Cell cell, Object value, int dataColumnIndex, int dataRowIndex) {
    if (value instanceof String) {
        String s = (String) value;
        boolean isPlainValue = true;
        if (isToWriteAsComment(dataColumnIndex)) {
            // if this schema data column is dedicated as comment 
            isPlainValue = false;/*from  w w  w.j a va 2 s.  c  o  m*/
            if (firstRowIsHeader == false || dataRowIndex > 0) {
                // avoid set comment for the header line
                setCellComment(cell, s);
            }
        }
        if (isToWriteAsLink(dataColumnIndex)) {
            // if this schema data column is dedicated as hyper link
            if (firstRowIsHeader == false || dataRowIndex > 0) {
                // avoid set hyper-links for the header line
                setCellHyperLink(cell, s);
                isPlainValue = false;
            }
        }
        if (isPlainValue) {
            if (s.startsWith("=")) {
                int rowNum = cell.getRow().getRowNum();
                cell.setCellFormula(getFormular(s, rowNum));
                cell.setCellType(CellType.FORMULA);
            } else {
                cell.setCellValue(s);
                cell.setCellType(CellType.STRING);
            }
        }
    } else if (value instanceof Integer) {
        cell.setCellValue((Integer) value);
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Boolean) {
        cell.setCellValue((Boolean) value);
        cell.setCellType(CellType.BOOLEAN);
    } else if (value instanceof Long) {
        cell.setCellValue((Long) value);
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof BigInteger) {
        cell.setCellValue(((BigInteger) value).longValue());
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof BigDecimal) {
        cell.setCellValue(((BigDecimal) value).doubleValue());
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Double) {
        cell.setCellValue((Double) value);
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Float) {
        cell.setCellValue((Float) value);
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Short) {
        cell.setCellValue((Short) value);
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Number) {
        cell.setCellValue(Double.valueOf(((Number) value).doubleValue()));
        cell.setCellType(CellType.NUMERIC);
    } else if (value instanceof Date) {
        if (writeZeroDateAsNull && GenericDateUtil.isZeroDate((Date) value)) {
            cell.setCellType(CellType.BLANK);
        } else {
            cell.setCellValue((Date) value);
            cell.setCellType(CellType.NUMERIC);
        }
    } else if (value != null) {
        cell.setCellValue(value.toString());
        cell.setCellType(CellType.STRING);
    } else if (writeNullValues && value == null) {
        cell.setCellType(CellType.BLANK);
    }
    if (isDataRow(dataRowIndex)) {
        setupStyle(cell, dataRowIndex);
    }
}

From source file:de.jlo.talendcomp.excel.SpreadsheetReferencedCellInput.java

License:Apache License

private boolean fetchCurrentCellValue(Cell cell) {
    if (cell != null) {
        currentCell = cell;/*from  w w  w .j  a  v  a2  s. com*/
        currentCellValueString = getStringCellValue(cell);
        Comment comment = cell.getCellComment();
        if (comment != null) {
            currentCellComment = comment.getString().getString();
            currentCellCommentAuthor = comment.getAuthor();
        }
        CellType cellType = cell.getCellTypeEnum();
        if (cellType == CellType.BLANK) {
            currentCellValueClassName = "Object";
        } else if (cellType == CellType.STRING) {
            currentCellValueClassName = "String";
            currentCellValueObject = currentCellValueString;
        } else if (cellType == CellType.BOOLEAN) {
            currentCellValueClassName = "Boolean";
            currentCellValueBool = cell.getBooleanCellValue();
            currentCellValueObject = currentCellValueBool;
        } else if (cellType == CellType.ERROR) {
            currentCellValueClassName = "Byte";
            currentCellValueObject = cell.getErrorCellValue();
        } else if (cellType == CellType.FORMULA) {
            currentCellValueClassName = "String";
            currentCellFormula = cell.getCellFormula();
            currentCellValueString = getDataFormatter().formatCellValue(cell, getFormulaEvaluator());
            currentCellValueObject = currentCellValueString;
        } else if (cellType == CellType.NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                currentCellValueClassName = "java.util.Date";
                currentCellValueDate = cell.getDateCellValue();
                currentCellValueObject = currentCellValueDate;
            } else {
                currentCellValueClassName = "Double";
                currentCellValueNumber = cell.getNumericCellValue();
                currentCellValueObject = currentCellValueNumber;
            }
        }
        currentCellBgColor = getBgColor(cell);
        currentCellFgColor = getFgColor(cell);
        return currentCellValueObject != null;
    } else {
        return false;
    }
}

From source file:de.jlo.talendcomp.excel.SpreadsheetReferencedCellInput.java

License:Apache License

private String getStringCellValue(Cell cell) {
    String value = null;//from  w w  w  .j a  v  a 2 s  .c  o  m
    if (cell != null) {
        CellType cellType = cell.getCellTypeEnum();
        if (cellType == CellType.FORMULA) {
            value = getDataFormatter().formatCellValue(cell, getFormulaEvaluator());
        } else if (cellType == CellType.STRING) {
            if (returnURLInsteadOfName) {
                Hyperlink link = cell.getHyperlink();
                if (link != null) {
                    if (concatenateLabelUrl) {
                        String url = link.getAddress();
                        if (url == null) {
                            url = "";
                        }
                        String label = link.getLabel();
                        if (label == null) {
                            label = "";
                        }
                        value = label + "|" + url;
                    } else {
                        value = link.getAddress();
                    }
                } else {
                    value = cell.getStringCellValue();
                }
            } else {
                value = cell.getStringCellValue();
            }
        } else if (cellType == CellType.NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                Date d = cell.getDateCellValue();
                value = defaultDateFormat.format(d);
            } else {
                value = numberFormat.format(cell.getNumericCellValue());
            }
        } else if (cellType == CellType.BOOLEAN) {
            value = cell.getBooleanCellValue() ? "true" : "false";
        } else if (cellType == CellType.BLANK) {
            value = null;
        }
    }
    return value;
}

From source file:io.vulpine.lib.kalo.PoiUtil.java

License:Apache License

public static CellType translateType(final Imu imu) {
    final Poi.Type p = imu.getAnnotation().type();

    if (p.translation != null)
        return p.translation;

    final Class type = ClassUtils.dePrimitive(imu.getType());

    if (String.class.equals(type))
        return CellType.STRING;
    if (Number.class.isAssignableFrom(type))
        return CellType.NUMERIC;
    if (Boolean.class.equals(type))
        return CellType.BOOLEAN;

    return CellType.STRING;
}