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个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问