Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- angular button
- 옵저버블
- 검색
- Router
- summary
- Oracle LISTAGG 사용 예시
- angular animation
- 호버
- ajax 사용 예시
- Angular Router
- angular modal
- ApexChart
- angular route
- flex-1
- 아이오닉 스크롤 이벤트
- 셀렉트박스 커스텀
- 모달
- formgroup
- egov spring ajax 사용 예시
- mysql if
- scroll
- 앵귤러 애니메이션
- route
- 스크롤 이벤트 감지
- 스크롤 이벤트
- Ionic modal
- TAILWIND
- modal
- prisma
- 앵귤러 모달
Archives
- Today
- Total
깜놀하는 해므찌로
Spring Controller Java 엑셀파일 읽기 메소드 예시 / POI 라이브러리 본문
반응형
SMALL
@SuppressWarnings({ "resource", "deprecation" })
public List<SearchVO> xlsxReadList(String filePath) throws Exception{
List<SearchVO> outArray = new ArrayList<>();
FileInputStream fis = null;
XSSFWorkbook workbook = null;
try{
fis = new FileInputStream(filePath);
workbook = new XSSFWorkbook(fis); // 경로를 받아 XLS 파일을 읽는다.
XSSFSheet curSheet;
XSSFRow curRow;
XSSFCell curCell;
SearchVO outData;
String tarDir = "c:\\test";
// 현재 sheet 반환 (첫번째시트 : 0)
curSheet = workbook.getSheetAt(0);
// row 길이
int rowLength = curSheet.getPhysicalNumberOfRows();
// row(세로데이터) 탐색 for문 (row 0은 헤더정보이기 때문에 1부터 시작)
for(int rowIndex=1; rowIndex < rowLength; rowIndex++){
// 현재 row 반환
curRow = curSheet.getRow(rowIndex);
outData = new SearchVO();
String value;
// cell 길이
int cellLength = curRow.getPhysicalNumberOfCells();
// cell 최대 길이
int cellEnd = curRow.getLastCellNum();
System.out.println("cellLength :: "+ cellLength);
System.out.println("cellEnd :: "+ cellEnd);
// cell(가로데이터) 탐색 for문
for(int cellIndex = 0; cellIndex <= cellEnd; cellIndex++){
curCell = curRow.getCell(cellIndex);
// cell 스타일이 다르더라도 String으로 변환 받음
if(curCell != null){
switch (curCell.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA :
value = curCell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC :
value = (int)curCell.getNumericCellValue()+"";
break;
case HSSFCell.CELL_TYPE_STRING :
value = curCell.getStringCellValue()+"";
break;
case HSSFCell.CELL_TYPE_BLANK :
//value = curCell.getBooleanCellValue()+"";
value = "";
break;
case HSSFCell.CELL_TYPE_ERROR :
value = curCell.getErrorCellValue()+"";
break;
default :
value = new String();
break;
}
}else{
value = "-";
}
if(cellIndex == 0){ outData.setSeq(value);}
if(cellIndex == 1){ outData.setWorkDiv(value);}
if(cellIndex == 2){ outData.setPosition(value);}
if(cellIndex == 3){ outData.setId(value);}
if(cellIndex == 4){ outData.setName(value);}
if(cellIndex == 5){ outData.setEmail(value);}
if(cellIndex == 6){ outData.setRegDate(value);}
} // for
outArray.add(outData);
} // for
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(workbook != null) {
workbook = null;
}
if(fis != null){
fis.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
return outArray;
}
반응형
LIST
'IT' 카테고리의 다른 글
MyBatis SQL XML 작성 시 기본적인 태그 기능 정리 (0) | 2022.09.20 |
---|---|
JavaScript charCodeAt (0) | 2022.09.19 |
Egov Spring Controller Java 엑셀 업로드 메소드 예시 (0) | 2022.09.17 |
monthPicker 한 달 달력 예시 / JavaScript 한 달 달력 (0) | 2022.09.16 |
SQL MOD 함수 (0) | 2022.09.15 |