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:com.pe.nisira.movil.view.action.RegistroPaleta.java

public void getExcelTablePaletaList(List sheetData) {
    try {// ww  w .j av a2  s . c om
        if (sheetData.size() > 0) {
            List<Paleta> lista = new ArrayList<Paleta>();
            Paleta paleta = new Paleta();
            for (int i = 1; i < sheetData.size(); i++) {
                List list = (List) sheetData.get(i);
                paleta = new Paleta();
                for (int j = 0; j < list.size(); j++) {
                    Cell cell = (Cell) list.get(j);
                    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                        System.out.print(cell.getNumericCellValue());
                    } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                        System.out.print(cell.getRichStringCellValue());
                    } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                        System.out.print(cell.getBooleanCellValue());
                    }
                    switch (j) {
                    case 0:
                        paleta.setIdempresa(cell.getRichStringCellValue().getString());
                        break;
                    case 1:
                        paleta.setIdregistropaleta(cell.getRichStringCellValue().getString());
                        break;
                    case 2:
                        paleta.setIdproducto(cell.getRichStringCellValue().getString());
                        break;
                    case 3:
                        paleta.setNropaleta(cell.getRichStringCellValue().getString());
                        break;
                    case 4:
                        paleta.setDescproducto(cell.getRichStringCellValue().getString());
                        break;
                    case 5:
                        paleta.setIdmedida(cell.getRichStringCellValue().getString());
                        break;
                    case 6:
                        paleta.setCantidad(cell.getRichStringCellValue().getString());
                        break;
                    case 7:
                        paleta.setPeso(Double.parseDouble(cell.getRichStringCellValue().getString()));
                        break;
                    case 8:
                        paleta.setIdlotep(cell.getRichStringCellValue().getString());
                        break;
                    case 9:
                        paleta.setIdcliente(cell.getRichStringCellValue().getString());
                        break;
                    case 10:
                        paleta.setIdclieprov(cell.getRichStringCellValue().getString());
                        break;
                    case 11:
                        paleta.setIdenvase(cell.getRichStringCellValue().getString());
                        break;
                    case 12:
                        paleta.setDescenvase(cell.getRichStringCellValue().getString());
                        break;
                    case 13:
                        paleta.setCerrado(cell.getRichStringCellValue().getString());
                        break;
                    case 14:
                        paleta.setNromanual(cell.getRichStringCellValue().getString());
                        break;
                    }
                    if (j < list.size() - 1) {
                        System.out.print(", ");
                    }
                }
                lista.add(paleta);
                System.out.println("");
            }
            System.out.println("Terminado ...");
            this.listPaleta = lista;
            RequestContext.getCurrentInstance().update("datos:tbl");
        }
    } catch (Exception ex) {

    }
}

From source file:com.photon.phresco.eshop.utils.ServiceUtil.java

License:Apache License

public static String getValue(Cell cell) {
    if (cell == null) {
        return null;
    }/*from   ww  w  .j a  va 2 s.  c om*/

    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return cell.getStringCellValue();
    }

    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return String.valueOf(cell.getNumericCellValue());
    }

    if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
        return String.valueOf(cell.getBooleanCellValue());
    }

    if (Cell.CELL_TYPE_BLANK == cell.getCellType()) {
        return null;
    }

    return null;
}

From source file:com.plugin.excel.util.ExcelUtil.java

License:Apache License

/**
 * @param oldCell//from   w  ww . ja va2  s .c  o  m
 * @param newCell
 * @param styleMap
 */
public static void copyCell(Cell oldCell, Cell newCell, Map<Integer, CellStyle> styleMap) {
    if (styleMap != null) {
        if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
            newCell.setCellStyle(oldCell.getCellStyle());
        } else {
            int stHashCode = oldCell.getCellStyle().hashCode();
            CellStyle newCellStyle = styleMap.get(stHashCode);
            if (newCellStyle == null) {
                newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
                newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
                styleMap.put(stHashCode, newCellStyle);
            }
            newCell.setCellStyle(newCellStyle);
        }
    }
    switch (oldCell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        newCell.setCellValue(oldCell.getStringCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        newCell.setCellValue(oldCell.getNumericCellValue());
        break;
    case Cell.CELL_TYPE_BLANK:
        newCell.setCellType(Cell.CELL_TYPE_BLANK);
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        newCell.setCellValue(oldCell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_ERROR:
        newCell.setCellErrorValue(oldCell.getErrorCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        newCell.setCellFormula(oldCell.getCellFormula());
        break;
    default:
        break;
    }

}

From source file:com.qihang.winter.poi.excel.imports.CellValueServer.java

License:Apache License

/**
 * ??/*from   w  w  w.  j  a  va 2 s . c om*/
 * 
 * @param xclass
 * @param cell
 * @param entity
 * @return
 */
private Object getCellValue(String xclass, Cell cell, ExcelImportEntity entity) {
    if (cell == null) {
        return "";
    }
    Object result = null;
    // ?,cell??
    if ("class java.util.Date".equals(xclass) || ("class java.sql.Time").equals(xclass)) {
        if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
            // ?
            result = cell.getDateCellValue();
        } else {
            cell.setCellType(Cell.CELL_TYPE_STRING);
            result = getDateData(entity, cell.getStringCellValue());
        }
        if (("class java.sql.Time").equals(xclass)) {
            result = new Time(((Date) result).getTime());
        }
    } else if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        result = cell.getNumericCellValue();
    } else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
        result = cell.getBooleanCellValue();
    } else {
        result = cell.getStringCellValue();
    }
    return result;
}

From source file:com.qihang.winter.poi.excel.imports.ExcelImportServer.java

License:Apache License

/**
 * ?key,?????//from   w  w  w .  j av a 2s . c o m
 *
 * @author Zerrion
 * @date 2013-11-21
 * @param cell
 * @return
 */
private String getKeyValue(Cell cell) {
    Object obj = null;
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        obj = cell.getStringCellValue();
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        obj = cell.getBooleanCellValue();
        break;
    case Cell.CELL_TYPE_NUMERIC:
        obj = cell.getNumericCellValue();
        break;
    case Cell.CELL_TYPE_FORMULA:
        obj = cell.getCellFormula();
        break;
    }
    return obj == null ? null : obj.toString().trim();
}

From source file:com.qihang.winter.poi.util.PoiSheetUtility.java

License:Apache License

private static void cloneCell(Cell cNew, Cell cOld) {
    cNew.setCellComment(cOld.getCellComment());
    cNew.setCellStyle(cOld.getCellStyle());

    switch (cNew.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN: {
        cNew.setCellValue(cOld.getBooleanCellValue());
        break;//from   w w w  .  j av a2  s  .c om
    }
    case Cell.CELL_TYPE_NUMERIC: {
        cNew.setCellValue(cOld.getNumericCellValue());
        break;
    }
    case Cell.CELL_TYPE_STRING: {
        cNew.setCellValue(cOld.getStringCellValue());
        break;
    }
    case Cell.CELL_TYPE_ERROR: {
        cNew.setCellValue(cOld.getErrorCellValue());
        break;
    }
    case Cell.CELL_TYPE_FORMULA: {
        cNew.setCellFormula(cOld.getCellFormula());
        break;
    }
    }

}

From source file:com.qualogy.qafe.service.DocumentServiceImpl.java

License:Apache License

String getCellValue(Cell cell) {
    String value = null;// www.ja v  a2 s .c o m
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_NUMERIC:
    case Cell.CELL_TYPE_STRING:
        value = cell.toString();
        break;
    // case Cell.CELL_TYPE_NUMERIC:
    // value = cell.getNumericCellValue() + "";
    // break;
    // case Cell.CELL_TYPE_STRING:
    // value = cell.getStringCellValue();
    // break;
    case Cell.CELL_TYPE_FORMULA:
        value = cell.getCellFormula();
        break;
    case Cell.CELL_TYPE_BLANK:
        ;
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = cell.getBooleanCellValue() + "";
        break;
    case Cell.CELL_TYPE_ERROR:
        value = cell.getErrorCellValue() + "";
        break;
    }
    return value != null ? value.trim() : value;
}

From source file:com.quanticate.opensource.spreadsheetexcerpt.excerpt.POIExcerpterAndMerger.java

License:Apache License

private void excerpt(Workbook wb, List<Sheet> sheetsToKeep, OutputStream output) throws IOException {
    // Make the requested sheets be read only
    Set<String> keepNames = new HashSet<String>();
    for (Sheet s : sheetsToKeep) {
        keepNames.add(s.getSheetName());
        for (Row r : s) {
            for (Cell c : r) {
                if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
                    switch (c.getCachedFormulaResultType()) {
                    case Cell.CELL_TYPE_NUMERIC:
                        double vd = c.getNumericCellValue();
                        c.setCellType(Cell.CELL_TYPE_NUMERIC);
                        c.setCellValue(vd);
                        break;
                    case Cell.CELL_TYPE_STRING:
                        RichTextString vs = c.getRichStringCellValue();
                        c.setCellType(Cell.CELL_TYPE_STRING);
                        c.setCellValue(vs);
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        boolean vb = c.getBooleanCellValue();
                        c.setCellType(Cell.CELL_TYPE_BOOLEAN);
                        c.setCellValue(vb);
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        c.setCellType(Cell.CELL_TYPE_BLANK);
                        break;
                    }/*from  www  .j  a va 2s. c om*/
                }
            }
        }
    }

    // Remove all the other sheets
    // Note - work backwards! Avoids order changing under us
    for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) {
        String name = wb.getSheetName(i);
        if (!keepNames.contains(name)) {
            wb.removeSheetAt(i);
        }
    }

    // Save
    wb.write(output);
}

From source file:com.quanticate.opensource.spreadsheetexcerpt.excerpt.POIExcerpterAndMerger.java

License:Apache License

private void merge(Workbook excerptWB, Workbook fullWB, String[] sheetsToMerge, OutputStream output)
        throws IOException {
    // Identify the sheets in both workbooks
    List<Sheet> sourceSheets = identifySheets(sheetsToMerge, excerptWB);
    List<Sheet> destSheets = identifySheets(sheetsToMerge, fullWB);

    // Process each sheet from the excerpt in turn
    for (int i = 0; i < sheetsToMerge.length; i++) {
        Sheet source = sourceSheets.get(i);
        Sheet dest = destSheets.get(i);/*from   w  w w. j av  a  2s.c  o  m*/

        for (Row srcR : source) {
            for (Cell srcC : srcR) {
                if (srcC.getCellType() == Cell.CELL_TYPE_FORMULA
                        || srcC.getCellType() == Cell.CELL_TYPE_ERROR) {
                    // Don't merge these kinds of cells
                } else {
                    Row destR = dest.getRow(srcR.getRowNum());
                    if (destR == null) {
                        // Newly added row to the excerpt file, skip this
                    } else {
                        Cell destC = destR.getCell(srcC.getColumnIndex());
                        if (destC == null && srcC.getCellType() == Cell.CELL_TYPE_BLANK) {
                            // Both are empty, don't need to do anything
                        } else {
                            if (destC == null)
                                destC = destR.createCell(srcC.getColumnIndex(), srcC.getCellType());

                            // Sync contents
                            if (srcC.getCellType() == Cell.CELL_TYPE_BLANK) {
                                destC.setCellType(Cell.CELL_TYPE_BLANK);
                            } else if (srcC.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                                destC.setCellValue(srcC.getBooleanCellValue());
                            } else if (srcC.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                destC.setCellValue(srcC.getNumericCellValue());
                            } else if (srcC.getCellType() == Cell.CELL_TYPE_STRING) {
                                destC.setCellValue(srcC.getStringCellValue());
                            }

                            // Sync formatting rules
                            // TODO
                        }
                    }
                }
            }
        }
    }

    // Re-evaluate all the formulas in the destination workbook, now that
    //  we have updated cells in it
    FormulaEvaluator eval = fullWB.getCreationHelper().createFormulaEvaluator();
    eval.evaluateAll();

    // Save the new file
    fullWB.write(output);
}

From source file:com.rapidminer.operator.nio.Excel2007SheetTableModel.java

License:Open Source License

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Cell cell;
    if (config != null) {
        Row row = sheet.getRow(rowIndex + config.getRowOffset());
        if (row == null) {
            return null;
        }/*from   w w w. j a  va2s . c  om*/
        cell = row.getCell(columnIndex + config.getColumnOffset());
    } else {
        Row row = sheet.getRow(rowIndex);
        if (row == null) {
            return null;
        }
        cell = row.getCell(columnIndex);
    }
    if (cell == null) {
        return null;
    }
    if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
        return cell.getBooleanCellValue();
    } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        return cell.getStringCellValue();
    } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        if (HSSFDateUtil.isCellDateFormatted(cell)) {
            return cell.getDateCellValue();
        } else {
            return cell.getNumericCellValue();
        }
    } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
        return cell.getErrorCellValue();
    } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        return cell.getNumericCellValue();
    } else {
        // last resort, should not come to this
        // maybe return null?
        return "";
    }
}