[Spring] POI로 Excel 읽기만
for (int i = 0; i < 3; i++) {
FileInputStream file;
try {
String path = resourceLoader.getResource("resources/4.xlsx").getURI().getPath();
file = new FileInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
for (int j = 2; j < rows; j++) {
XSSFRow row = sheet.getRow(j);
if (row == null) {
continue;
}
AbuttonDTO dto = new AbuttonDTO();
Date date = row.getCell(0).getDateCellValue();
String regDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
dto.setRegDate(regDate);
dto.setSite(row.getCell(1).getStringCellValue());
dto.setSiteTitle(row.getCell(2).getStringCellValue());
dto.setKind(row.getCell(3).getStringCellValue());
dto.setUrl(row.getCell(4).getStringCellValue());
dto.setUrlTitle(row.getCell(5).getStringCellValue());
dto.setName(row.getCell(6).getStringCellValue());
listResult.add(dto);
}
System.out.println(listResult);
model.addAttribute("list", listResult);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}