poi导入表格,cell内容格式不匹配 cannot cast to

先全部以String的形式接收,然后转换成你需要的类型。

public static String getCellValue(Cell cell) {
		String re = "";
		if (null != cell) {
			switch (cell.getCellType()) {
			// 数字
			case HSSFCell.CELL_TYPE_NUMERIC:
				re = (int) cell.getNumericCellValue() + "";
				break;
			// 字符串
			case HSSFCell.CELL_TYPE_STRING:
				re = cell.getStringCellValue();
				break;
			// Boolean
			case HSSFCell.CELL_TYPE_BOOLEAN:
				re = cell.getBooleanCellValue() + "";
				break;
			// 公式
			case HSSFCell.CELL_TYPE_FORMULA:
				re = cell.getCellFormula() + "";
				break;
			// 空值
			case HSSFCell.CELL_TYPE_BLANK:
				re = "";
				break;
			// 故障
			case HSSFCell.CELL_TYPE_ERROR:
				re = "";
				break;
			default:
				re = "";
				break;
			}
		}
		return re;
	}

 

你可能感兴趣的:(java,poi,cannot,cast,to)