List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getPhysicalNumberOfRows
@Override public int getPhysicalNumberOfRows()
From source file:ve.zoonosis.model.imports.VacunadosDiarioPorMunicipio.java
License:Apache License
private void cargarObjects(HSSFSheet sheet, int row, int column, Object value) throws ParseException { if (value != null) { int monthIndex = Arrays.binarySearch(months, sheet.getSheetName(), new Comparator<String>() { @Override/* w ww . ja v a 2 s .c o m*/ public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); if (monthIndex == -1) { return; } int dia = getCellHeaderValue(sheet, 0, column); monthIndex++; String fecha = dia + "/" + monthIndex; HashMap<String, Vacunacion> m = vacunacion.get(fecha); if (m == null) { m = new HashMap<>(); } String parroquia = obtenrValor(sheet.getRow(row).getCell(0)); Vacunacion v = m.get(parroquia); if (v == null) { v = new Vacunacion(format.parse(fecha + "/" + year), new Semana( (String) getCellHeaderValue(sheet, sheet.getPhysicalNumberOfRows() - 1, column), year)); v.setParroquia(new Parroquia(parroquia, municipio)); v.getRegistroVacunacion().add(new RegistroVacunacion(v, LoginController.getUsuario())); } RegistroVacunacion rv = v.getRegistroVacunacion().get(0); rv.getVacunacion_has_Animal().add(new RegistroVacunacion_has_Animal(rv, new Animal((String) obtenrValor(sheet.getRow(1).getCell(column))), (Integer) value)); m.put(parroquia, v); vacunacion.put(fecha, m); } }
From source file:vone.HSSFReadWrite.java
License:Apache License
/** * Method main// w w w.j a v a2s .co m * * Given 1 argument takes that as the filename, inputs it and dumps the cell * values/types out to sys.out.<br/> * * given 2 arguments where the second argument is the word "write" and the * first is the filename - writes out a sample (test) spreadsheet see * {@link HSSFReadWrite#testCreateSampleSheet(String)}.<br/> * * given 2 arguments where the first is an input filename and the second an * output filename (not write), attempts to fully read in the spreadsheet * and fully write it out.<br/> * * given 3 arguments where the first is an input filename and the second an * output filename (not write) and the third is "modify1", attempts to read * in the spreadsheet, deletes rows 0-24, 74-99. Changes cell at row 39, col * 3 to "MODIFIED CELL" then writes it out. Hence this is "modify test 1". * If you take the output from the write test, you'll have a valid scenario. */ @SuppressWarnings("deprecation") public static void main(String[] args) { if (args.length < 1) { System.err.println("At least one argument expected"); return; } String fileName = args[0]; try { if (args.length < 2) { HSSFWorkbook wb = HSSFReadWrite.readFile(fileName); System.out.println("Data dump:\n"); for (int k = 0; k < wb.getNumberOfSheets(); k++) { HSSFSheet sheet = wb.getSheetAt(k); int rows = sheet.getPhysicalNumberOfRows(); System.out.println("Sheet " + k + " \"" + wb.getSheetName(k) + "\" has " + rows + " row(s)."); for (int r = 0; r < rows; r++) { HSSFRow row = sheet.getRow(r); if (row == null) { continue; } // int cells = row.getPhysicalNumberOfCells(); int cells = row.getLastCellNum(); System.out.println("\nROW " + row.getRowNum() + " has " + cells + " cell(s)."); for (int c = 0; c < cells; c++) { HSSFCell cell = row.getCell(c); String value = null; if (cell == null) { System.out.println("CELL col=" + c + " VALUE= Empty"); continue; } switch (cell.getCellTypeEnum()) { case FORMULA: value = "FORMULA value=" + cell.getCellFormula(); break; case NUMERIC: value = "NUMERIC value=" + cell.getNumericCellValue(); break; case STRING: value = "STRING value=" + cell.getStringCellValue(); break; default: } System.out.println("CELL col=" + cell.getColumnIndex() + " VALUE=" + value); } } } wb.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:ypcnv.views.impl.FileXLS.java
License:Open Source License
/** * Search for an a row with the data columns headers. * /*w w w. j av a 2s . c o m*/ * @param workbook * - where to search. * @return The row number (zero based). * @throws FileViewException */ private HSSFRow findHeaderRow(HSSFWorkbook workbook) throws FileViewException { if (xlsWorkbook.getNumberOfSheets() > 1) { String message = String.format( "There is more than one worksheet in workbook file '%s'. Will use the first one.", ((File) address).getAbsoluteFile()); LOG.info(message); } int choosenSheetIdx = 0; // zero based int headerRowIdx = 0; // zero based HSSFSheet currentSheet = xlsWorkbook.getSheetAt(choosenSheetIdx); if (currentSheet.getPhysicalNumberOfRows() == 0) { createHeaderRow(currentSheet, headerRowIdx); } HSSFRow headerRow = currentSheet.getRow(headerRowIdx); if (headerRow == null) { String message = String.format(FileXLSMeta.ERR_MESSAGE_NO_HEADER_ROW, choosenSheetIdx, headerRowIdx, ((File) address).getAbsoluteFile()); LOG.error(message); throw new FileViewException(null, "Contact2k3Xls.FileViewException()", message); } return headerRow; }