public void simpleImport(InputStream iStream) throws IOException {
try {
// 验证excel格式
//List<MaintenanceSettlementExportDto> list = new ArrayList<MaintenanceSettlementExportDto>();
//MaintenanceSettlementExportDto dto = null;
Workbook wb = new HSSFWorkbook(iStream);
Sheet sheet = wb.getSheetAt(0);
Row row = null;
Cell cell = null;
for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
row = sheet.getRow(i);
for (int j = 0; j < row.getLastCellNum() + 1; j++) {
cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC: // 数字
System.out.print(cell.getNumericCellValue() + " ");
break;
case Cell.CELL_TYPE_STRING: // 字符串
System.out.print(cell.getStringCellValue() + " ");
break;
case Cell.CELL_TYPE_BOOLEAN: // Boolean
System.out.println(cell.getBooleanCellValue() + " ");
break;
case Cell.CELL_TYPE_FORMULA: // 公式
System.out.print(cell.getCellFormula() + " ");
break;
case Cell.CELL_TYPE_BLANK: // 空值
System.out.println(" ");
break;
case Cell.CELL_TYPE_ERROR: // 故障
System.out.println(" ");
break;
default:
System.out.print("未知类型 ");
break;
}
}
}
}
} catch (RuntimeException e) {
logger.error("导入EXCEL 工具类异常", e);
throw new RuntimeException("导入 EXCEL 工具类异常");
}
}
poi读取excel内容
最新推荐文章于 2024-07-05 14:30:10 发布