(可以解析文本、日期、数值、公式单元格、布尔、空值)
1、解析数值型保留两位小数,日期格式为yyyy-mm-dd以及公式型单元格
/**
* 获取cell中的值
* @param cell
* @return
*/
private String getCellValue(HSSFCell cell) {
if (cell != null) {
String value = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC: // 数值型
DecimalFormat df = new DecimalFormat("#.##");
if (HSSFDateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
// 如果是date类型则 ,获取该cell的date值
//value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString();
} else { // 纯数字
value = df.format(cell.getNumericCellValue());
}
return value;
case HSSFCell.CELL_TYPE_STRING: // 字符串型
value = cell.getRichStringCellV