private String getValue (HSSFCell hssfCell) {
switch (hssfCell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
String cellValue = "";
if (HSSFDateUtil.isCellDateFormatted(hssfCell)) {
System.out.println("hssfCell="+ hssfCell.getNumericCellValue());
Double d = hssfCell.getNumericCellValue();
System.out.println("d="+ d);
Date date = HSSFDateUtil.getJavaDate(d);
System.out.println("date=" + sdf.format(date));
cellValue = sdf.format(date);
System.out.println("cellValue=" + cellValue);
}
else{
DecimalFormat df = new DecimalFormat("#.####");
cellValue = df.format(hssfCell.getNumericCellValue());
}
return cellValue;
case HSSFCell.CELL_TYPE_STRING:
return hssfCell.getStringCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return hssfCell.getCellFormula();
case HSSFCell.CELL_TYPE_BLANK:
return "";
case HSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf(hssfCell.getBooleanCellValue());
}
return "";
}
输出: