POI和JXL中日期无法显示问题

在用POI和JXL进行日期处理时,日期格式为“2012/04/09”时,获取到的结果常常为3422.2之类的数字,如果用格式“2012.04.09”则能正常显示,原因是在处理过程中。将日期也认为是数字类型。具体解决方法如下:

POI的解决方案:

case HSSFCell.CELL_TYPE_NUMERIC:    
    if (HSSFDateUtil.isCellDateFormatted(cell)) {    
        double d = cell.getNumericCellValue();    
        Date date = HSSFDateUtil.getJavaDate(d);    
    }    



JXL解决方案:

if (cell.getType() == CellType.NUMBER) {    
    NumberCell nc = (NumberCell) cell;    
    XFRecord xfr = (XFRecord) nc.getCellFormat();    
    final int INDEX_OF_DATE = 58;    
    if(xfr.formatIndex == INDEX_OF_DATE) {    
        Date date = HSSFDateUtil.getJavaDate(nc.getValue());    
        content = dateformat.format(date);    
    }     
}
  

if (cell.getType() == CellType.NUMBER) { 
    NumberCell nc = (NumberCell) cell; 
    XFRecord xfr = (XFRecord) nc.getCellFormat(); 
    final int INDEX_OF_DATE = 58; 
if(xfr.formatIndex == INDEX_OF_DATE) { 
    Date date = HSSFDateUtil.getJavaDate(nc.getValue()); 
    content = dateformat.format(date); 
    } 
} 


你可能感兴趣的:(poi,JXL,sheet,cell,HSSFWorkbook)