项目中需要使用Excel导入数据,读取Excel单元格的方法如下:
private static String getStringCellValue(Cell cell) {// 获取单元格数据内容为字符串类型的数据
String strCell = "";
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case Cell.CELL_TYPE_FORMULA:
// cell.getCellFormula();
try {
/*
* 此处判断使用公式生成的字符串有问题,因为HSSFDateUtil.isCellDateFormatted(cell)判断过程中cell
* .getNumericCellValue();方法会抛出java.lang.NumberFormatException异常
*/
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
strCell = (date.getYear() + 1900) + "-" + (date.getMonth() + 1) +"-" + date.getDate();
break;
} else {
strCell = String.valueOf(cell.getNumericCellValu