프로그래밍/JAVA
StreamingReader 엑셀파일 읽어보기
hangbeeeeeen
2021. 12. 23. 12:57
public Map<String, Object> read(MultipartFile multipartFile){
InputStream is = multipartFile.getInputStream();
Workbook workbook = StreamingReader.builder()
.rowCacheSize(100)
.bufferSize(4096)
.open(is);
Sheet sheet = workbook.getSheetAt(0);
Cell cell = null;
int totalColumns = 0;
for (Row row : sheet) {
if(row.getRowNum() == 0) {
totalColumns = row.getLastCellNum(); //첫 행에서 totalColumn 사이즈를 가져옴
}
for (int i = 0; i <totalColumns; i++) { //이렇게 사용하는 경우 빈 셀을 구분할 수 있음
cell = row.getCell(i);
if(cell != null){
cell.getStringCellValue(); //셀 데이터
}
}
}
}
반응형