- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
[Apache POI] 날짜 서식의 셀 데이터 읽기 본문
날짜 서식의 셀을 읽을 때 cell.getType() 값이 Cell.CELL_TYPE_NUMERIC 이 되서 당황했는데,
DateUtil.isCellDateFormatted(cell) 의 값이 true 이면
String.valueOf(cell.getDateCellValue()); 로 날짜 문자열을 얻으면 된다.
사용 Library:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
참조:
http://lovelyjk.tistory.com/28
http://stackoverflow.com/questions/10857209/issue-reading-in-a-cell-from-excel-with-apache-poi
private String getCellValue(FormulaEvaluator formulaEval, Cell cell) {
String cellString = "";
if( cell != null ) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING)
cellString = cell.getStringCellValue();
else if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
if( DateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
cellString = new SimpleDateFormat("yyyy-MM-dd").format(date);
}
else
cellString = String.valueOf(cell.getNumericCellValue());
}
else {
CellValue evaluate = formulaEval.evaluate(cell);
if( evaluate != null )
cellString = evaluate.formatAsString();
}
}
return cellString.trim();
}
'Java' 카테고리의 다른 글
Crystal Report 자료 (0) | 2015.06.16 |
---|---|
[공개SW 툴 가이드] JUnit (0) | 2015.06.11 |
[Apache POI] xlsx 파일을 xls 파일로 변환하는 메서드 (0) | 2015.04.29 |
Excel (xls포맷) Form Control (Checkbox) 상태 읽기. (0) | 2015.04.27 |
MyBatis를 이용해서 이미지 파일을 DB에 저장하고 불러오기 (0) | 2015.04.20 |