2013-09-23 4 views
1

1:20 시간 값이 (1:20:00) 인 셀이 있습니다. 아파치 포이 3.9으로 어떻게 읽을 수 있습니까? 코드에서 두 개의 셀 유형을 확인하고 시간 값을 읽으면 CELL_TYPE_NUMERIC으로, 1:200이됩니다. 정확히 1:20을 어떻게 읽을 수 있습니까? 고맙습니다!xls/xlsx에서 Apache POI 3.9로 시간 형식을 읽는 방법은 무엇입니까?

switch (cell.getCellType()) { 
    case HSSFCell.CELL_TYPE_NUMERIC: 
     cellValue = String.valueOf((int) (cell.getNumericCellValue())); 
     break; 
    case HSSFCell.CELL_TYPE_STRING: 
     cellValue = cell.getStringCellValue(); 
     break; 
} 

답변

1

나는 그것을했다 !!

switch (cell.getCellType()) { 
    case HSSFCell.CELL_TYPE_NUMERIC: 
     if(DateUtil.isCellDateFormatted(cell)) { 
      cellValue = new DataFormatter().formatCellValue(cell); 
     } else { 
      cellValue = String.valueOf((int) (cell.getNumericCellValue())); 
     } 
     break; 
    case HSSFCell.CELL_TYPE_STRING: 
     cellValue = cell.getStringCellValue(); 
     break; 
} 
+1

style.setDataFormat (HSSFDataFormat.getBuiltinFormat ("@")) .// 데이터가 다른 형식으로되어있는 경우도 .IT 그것이 문제 것이다 String.While 표시로서 취급한다. – swamy