private String getContents(Cell cell) { DateCell dCell=null; if(cell.getType() == CellType.DATE) { dCell = (DateCell)cell; // System.out.println("Value of Date Cell is: " + dCell.getDate()); // ==> Value of Date Cell is: Thu Apr 22 02:00:00 CEST 2088 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); // System.out.println(sdf.format(dCell.getDate())); // ==> 2088-04-22 return sdf.format(dCell.getDate()); } // possibly manage other types of cell in here if needed for your goals // read more: http://www.quicklyjava.com/reading-excel-file-in-java-datatypes/#ixzz2fYIkHdZP return cell.getContents(); }
public List<Result> read(File inputWorkbook) throws IOException { List<Result> list = new ArrayList<Result>(); Workbook w; try { w = Workbook.getWorkbook(inputWorkbook); // Get the first sheet Sheet sheet = w.getSheet(0); // Loop over first 10 column and lines for (int j = 1; j < sheet.getRows(); j++) { Result rs= new Result(); Cell cell0 = sheet.getCell(0, j); for (int i = 0; i < sheet.getColumns(); i++) { Cell cell = sheet.getCell(i, j); CellType type = cell.getType(); if (cell.getType() == CellType.LABEL) { System.out.println("I got a label " + cell.getContents()); } if (cell.getType() == CellType.NUMBER) { System.out.println("I got a number " + cell.getContents()); } } } } catch (Exception e) { e.printStackTrace(); } return list; }
CellType type = cell.getType(); if (type == CellType.LABEL) { System.out.print(cell.getContents() + ";");
for (int i = 0; i < sheet.getRows(); i++) { Cell cell = sheet.getCell(j, i); CellType type = cell.getType(); if (cell.getType() == CellType.LABEL) { System.out.println("I got a label " + cell.getContents()); if (cell.getType() == CellType.NUMBER) { System.out.println("I got a number " + cell.getContents());
CellType type = cell2.getType();
CellType type = cell.getType();
for (int i = 0; i < sheet.getRows(); i++) { Cell cell = sheet.getCell(j, i); CellType type = cell.getType(); if (type == CellType.LABEL) { System.out.println("I got a label "