private String getValue(XSSFCell hssfCell) { if (hssfCell == null) { // 返回布爾類型的值 return ""; } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) { // 返回布爾類型的值 return String.valueOf(hssfCell.getBooleanCellValue()); } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) { // 返回數值類型的值 DecimalFormat df = new DecimalFormat("#"); return df.format(hssfCell.getNumericCellValue()); } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_FORMULA) { // 返回公式類型的值 return hssfCell.getCTCell().getV(); } else { // 返回字符串類型的值 return String.valueOf(hssfCell.getStringCellValue()); } } private Date getDateValue(XSSFCell hssfCell) throws ParseException { if (hssfCell.getCellType() != hssfCell.CELL_TYPE_STRING && hssfCell.getCellType() != hssfCell.CELL_TYPE_FORMULA) { return HSSFDateUtil.getJavaDate(hssfCell.getNumericCellValue()); } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_FORMULA) { // 返回數值類型的值 return DateUtils.parseDate(hssfCell.getCTCell().getV(), "yyyy/MM/dd"); } else { return DateUtils.parseDate(hssfCell.getStringCellValue(), "yyyy/MM/dd"); } }