public static void read(String excel) throws IOException {
File file = new File(excel);
if (!file.exists() || !file.isFile() || !file.canRead()) {
IOException ioe = new IOException("File Not Found : " + excel);
throw ioe;
}
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
ExcelExtractor extractor = new ExcelExtractor(wb);
extractor.setFormulasNotResults(true);
extractor.setIncludeSheetNames(false);
//System.out.println(extractor.getText());
public static void read(String excel) throws IOException {
// check file
File file = new File(excel);
if (!file.exists() || !file.isFile() || !file.canRead()) {
IOException ioe = new IOException("File Not Found : " + excel);
throw ioe;
}
// Workbook
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
// Text Extraction
ExcelExtractor extractor = new ExcelExtractor(wb);
extractor.setFormulasNotResults(true);
extractor.setIncludeSheetNames(false);
//System.out.println(extractor.getText());
// Getting cell contents
for (Row row : wb.getSheetAt(0)) {
for (Cell cell : row) {
// Cell Reference
CellReference cellRef = new CellReference(row.getRowNum(),
cell.getColumnIndex());
String key = cellRef.formatAsString();
//System.out.print(" - ");
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
excelValue.put(key, cell.getRichStringCellValue().getString());
break;
case Cell.CELL_TYPE_NUMERIC:
excelValue.put(key, String.valueOf(cell.getNumericCellValue()));
break;
case Cell.CELL_TYPE_BOOLEAN:
excelValue.put(key, String.valueOf(cell.getBooleanCellValue()));
break;
}
}
}
}
}