关于Java中使用POI包获取Excel单元格字符串值的说明

/**
 * 定义时间格式化对象
 */
public static DateFormat dfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

/**
 * 获取Excel单元格字符串值
 * 
 * @param cell
 *            Excel单元格
 * @return 返回单元格的字符串值
 */
public static String getCellValue(Cell cell) {
	// 定义单元格字符串值对象
	String value = null;
	// 判断单元格是否为空
	if (cell != null) {
		// 根据单元格数据类型获取字符串值
		switch (cell.getCellType()) {
		case Cell.CELL_TYPE_BLANK:
			// 空单元格返回空字符串
			value = "";
			break;
		case Cell.CELL_TYPE_BOOLEAN:
			// 布尔型单元格返回布尔字符串
			value = String.valueOf(cell.getBooleanCellValue());
			break;
		case Cell.CELL_TYPE_ERROR:
			// 无效单元格返回空
			value = null;
			break;
		case Cell.CELL_TYPE_FORMULA:
			// 函数单元格返回函数计算结果字符串
			Workbook wb = cell.getSheet().getWorkbook();
			CreationHelper crateHelper = wb.getCreationHelper();
			FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator();
			value = getCellValue(evaluator.evaluateInCell(cell));
			break;
		case Cell.CELL_TYPE_NUMERIC:
			// 数值单元格返回数值字符串
			if (DateUtil.isCellDateFormatted(cell)) {
				Date theDate = cell.getDateCellValue();
				value = dfDateTime.format(theDate);
			} else {
				value = NumberToTextConverter.toText(cell.getNumericCellValue());
			}
			break;
		case Cell.CELL_TYPE_STRING:
			// 字符串单元格返回字符串
			value = cell.getRichStringCellValue().getString();
			break;
		default:
			// 其他返回空
			value = null;
		}
	}
	// 返回单元格字符串值
	return value;
}