List of usage examples for org.apache.poi.ss.usermodel Cell getBooleanCellValue
boolean getBooleanCellValue();
From source file:update2viva.ConvertXLSX.java
static void readXls(File inputFile) { try {//from ww w . j av a2 s . c o m // Get the workbook instance for XLS file HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(inputFile)); // Get first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0); Cell cell; Row row; // Iterate through each rows from first sheet Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { row = rowIterator.next(); // For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: System.out.println(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: System.out.println(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: System.out.println(cell.getStringCellValue()); break; case Cell.CELL_TYPE_BLANK: System.out.println(" "); break; default: System.out.println(cell); } } } } catch (FileNotFoundException e) { System.err.println("Exception" + e.getMessage()); } catch (IOException e) { System.err.println("Exception" + e.getMessage()); } }
From source file:util.POIUtils.java
License:LGPL
/** * Gets the string value of a cell.// ww w. j a v a 2s . c om * * @param cell the cell to get the string value of * @return the string value of the specified cell */ private static String getStringValue(Cell cell) { if (cell != null) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: cell.setCellType(Cell.CELL_TYPE_NUMERIC); return formatNumber(cell.getNumericCellValue()); case Cell.CELL_TYPE_BOOLEAN: return Boolean.toString(cell.getBooleanCellValue()); default: return StringUtils.stripToNull(cell.getRichStringCellValue().getString()); } } return null; }
From source file:ve.zoonosis.model.imports.CasosDiarioPorMunicipio.java
License:Apache License
private <T> T obtenrValor(Cell c) { Object value;//from ww w. j ava 2 s . com switch (c.getCellType()) { case Cell.CELL_TYPE_STRING: value = c.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: value = ((Double) c.getNumericCellValue()).intValue(); break; case Cell.CELL_TYPE_BOOLEAN: value = c.getBooleanCellValue(); break; default: value = null; } return (T) value; }
From source file:XlsUtils.XlsComparator.java
/** * Obtiene el valor de una Cell de Excel * @param cell// w w w. jav a 2 s. co m * @return */ public static Object getCellValue(Cell cell) { Object result = null; if (cell != null) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { result = cell.getDateCellValue(); } else { if (cell.getNumericCellValue() == (int) cell.getNumericCellValue()) { result = (int) cell.getNumericCellValue(); } else { result = cell.getNumericCellValue(); } } break; case Cell.CELL_TYPE_STRING: result = cell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: result = cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_ERROR: result = null; break; } } return result; }