POI를 이용한 Excel ( *.xls, *.xlsx ) 읽기
Language/JAVA 2013. 11. 13. 17:13apache poi site : http://poi.apache.org/
int sheetNum = work.getNumberOfSheets();
log.error("\n# sheet num : " + sheetNum);
for( int loop = 0; loop < sheetNum; loop++){
HSSFSheet sheet = work.getSheetAt(loop);
int rows = sheet.getPhysicalNumberOfRows();
log.error("\n# sheet rows num : " + rows);
for( int rownum = 0; rownum < rows; rownum++){
HSSFRow row = sheet.getRow(rownum);
if(row != null){
int cells = row.getPhysicalNumberOfCells();
log.error("\n# row = " + row.getRowNum() + " / cells = " + cells);
for(int cellnum =0; cellnum < cells; cellnum++){
HSSFCell cell = row.getCell(cellnum);
if(cell != null){
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
params.put("CELL_TYPE_FORMULA"+cellnum, cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
params.put("CELL_TYPE_STRING"+cellnum, cell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
params.put("CELL_TYPE_BLANK"+cellnum, cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR :
params.put("CELL_TYPE_ERROR"+cellnum, cell.getErrorCellValue());
break;
......
default:
break;
}
}
log.error("\n CELL __ [params ] => " + params.toString());
}
}
}
}
int sheetNum = work.getNumberOfSheets();
log.error("\n# sheet num : " + sheetNum);
for( int loop = 0; loop < sheetNum; loop++){
XSSFSheet sheet = work.getSheetAt(loop);
int rows = sheet.getPhysicalNumberOfRows();
log.error("\n# sheet rows num : " + rows);
for( int rownum = 0; rownum < rows; rownum++){
XSSFRow row = sheet.getRow(rownum);
if(row != null){
int cells = row.getPhysicalNumberOfCells();
log.error("\n# row = " + row.getRowNum() + " / cells = " + cells);
for(int cellnum =0; cellnum < cells; cellnum++){
XSSFCell cell = row.getCell(cellnum);
if(cell != null){
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_FORMULA:
params.put("CELL_TYPE_FORMULA"+cellnum, cell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_STRING:
params.put("CELL_TYPE_STRING"+cellnum, cell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
params.put("CELL_TYPE_BLANK"+cellnum, cell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_ERROR :
params.put("CELL_TYPE_ERROR"+cellnum, cell.getErrorCellValue());
break;
......
default:
break;
}
}
log.error("\n CELL __ [params ] => " + params.toString());
}
}
}
}
출처 - http://enosent.tistory.com/30
'Language > JAVA' 카테고리의 다른 글
jdk7 file write (0) | 2013.11.14 |
---|---|
double 지수 표현 제거 (0) | 2013.11.13 |
Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable. (0) | 2013.09.17 |
JAXB: Marshalling and Unmarshalling CDATA block using EclipseLink MOXy (0) | 2013.09.03 |
.getClass() 와 .class의 차이점 (0) | 2013.08.29 |