private Workbook getWorkBook(String filePath) {
FileInputStream is = null;
try {
is = new FileInputStream(filePath);
if (filePath.toLowerCase().endsWith("xlsx")) {
return new XSSFWorkbook(is);
} else if (filePath.toLowerCase().endsWith("xls")) {
return new HSSFWorkbook(is);
} else {
throw new RuntimeException("excel解析異常");
}
} catch (IOException e) {
throw new RuntimeException("excel解析異常", e);
} finally {
IOUtils.closeQuietly(is);
}
}
Sheet sheet = workBook.getSheet("sheet1");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
double value = cell.getNumericCellValue();
String value = cell.getStringCellValue();