qq_36846253
qq_36846253
采纳率0%
2016-11-30 04:04 阅读 2.4k

POI 如何读取EXcel表,之后如何存入List集合中

FileInputStream fis = new FileInputStream(
"E:\215e_2016-11-28-15-06-00.xls");
HSSFWorkbook wb = new HSSFWorkbook(fis);
System.out.println(wb);
// 获取整个excel有多少个sheet
HSSFSheet sheet = wb.getSheetAt(0);
System.out.println(sheet);
// 总行数
int rowNum = sheet.getPhysicalNumberOfRows();
System.out.println(rowNum);
// 第一行
int sheetCount = wb.getNumberOfSheets();
System.out.println(sheetCount);
for (int i = 0; i < sheetCount; i++) {
sheet = wb.getSheetAt(i);
rowNum = sheet.getPhysicalNumberOfRows();
int cellNum = sheet.getRow(0).getPhysicalNumberOfCells();
for (int j = 0; j < rowNum; j++) {
HSSFRow row = sheet.getRow(j);
System.out.println(row);
for (short k = 0; k < cellNum; k++) {
HSSFCell cell = row.getCell(k);
System.out.println(cell);
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
System.out.println(cell.getStringCellValue());
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.println(cell.getNumericCellValue());
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
System.out.println(cell.getBooleanCellValue());
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
System.out.println("NULL");
} else {
System.out.println(cell.getDateCellValue());
}
}
}
}
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐