private String getValue(HSSFCell cell) {
String cellValue = "";
DecimalFormat df = new DecimalFormat("#.0000");
if(cell!=null){
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString().trim();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = this.doubleTrans(cell.getNumericCellValue());
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
cellValue = formater.format(d).toString();
}
// cellValue = df.format(cell.getNumericCellValue()).toString();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue()).trim();
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellValue = cell.getCellFormula();
break;
default:
cellValue = "";
}
}
return cellValue;
}
/**
* double为整数时取整
*/
private String doubleTrans(double d){
if(Math.round(d)-d==0){
return String.valueOf((long)d);
}
return String.valueOf(d);
}