java poi读取excel日期格式数据

public String getCell(HSSFCell cell) {
DecimalFormat df = new DecimalFormat("#");
if (cell == null)
return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
if(HSSFDateUtil.isCellDateFormatted(cell)){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString();
}
return df.format(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING:
System.out.println(cell.getStringCellValue());
return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_BLANK:
return "";
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() + "";
case HSSFCell.CELL_TYPE_ERROR:
return cell.getErrorCellValue() + "";
}
return "";
}

猜你喜欢

转载自zhoujun384475266.iteye.com/blog/2008057