1、获取单元格中的值
public String getStringValue(HSSFCell cell) {
if (cell == null)
return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_BLANK:
return "";
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() + "";
case HSSFCell.CELL_TYPE_NUMERIC: {
if (HSSFDateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
return sdf.format(cell.getDateCellValue());
} else {
double tmp = cell.getNumericCellValue();
if (tmp % (int) tmp == 0) {
return "" + (int) tmp;
}
return tmp + "";
}
}
case HSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
default:
return cell.getErrorCellValue() + "";
}
}