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(); //셀 데이터
}
}
}
}
반응형
'프로그래밍 > JAVA' 카테고리의 다른 글
Logback - Exception 로그 기록 (0) | 2023.10.10 |
---|---|
[SpringBoot] 배너 변경 (0) | 2021.12.30 |
HttpPost로 MultipartFile 전송 (0) | 2021.12.23 |
MultipartFile - File 변환 (0) | 2021.12.23 |