Java ApacheのpoiでExcelインポートを実現
本は前文に続く
poi Excelインポートの実現
poi Excelインポートの実現
@Override
public List importExcelStudent(String xlsPath) throws IOException {
List students = new ArrayList<>();
//
FileInputStream fileInputStream = new FileInputStream(xlsPath);
// excel
Workbook wb = new HSSFWorkbook(fileInputStream);
// excel
Sheet sheet = wb.getSheetAt(0);
// ( )
for (Row row : sheet) {
if (row.getRowNum() == 0) {
continue;
}
Student student = new Student();
student.setName(row.getCell(0).getStringCellValue());
student.setId(row.getCell(1).getStringCellValue());
student.setAge((int)row.getCell(2).getNumericCellValue());
student.setSex(row.getCell(3).getStringCellValue());
students.add(student);
}
fileInputStream.close();
return students;
}