/**
* 获取cell的
*
* @param cell
* @return
*/
public static String getCellValue(Cell cell) {
String strCell = "";
if (cell != null) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING://字符串类型
strCell = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC://数字类型
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式
SimpleDateFormat sdf = null;
// short dataFormat = cell.getCellStyle().getDataFormat();
sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = cell.getDateCellValue();
strCell = sdf.format(date);
} else {
strCell = String.valueOf(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN://boolean类型
strCell = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_BLANK:
strCell = "";
break;
default:
strCell = "";
break;
}
}
if (strCell.equals("") || strCell == null) {
strCell = "";
}
return strCell.trim();
}
* 获取cell的
*
* @param cell
* @return
*/
public static String getCellValue(Cell cell) {
String strCell = "";
if (cell != null) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING://字符串类型
strCell = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC://数字类型
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式
SimpleDateFormat sdf = null;
// short dataFormat = cell.getCellStyle().getDataFormat();
sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = cell.getDateCellValue();
strCell = sdf.format(date);
} else {
strCell = String.valueOf(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN://boolean类型
strCell = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_BLANK:
strCell = "";
break;
default:
strCell = "";
break;
}
}
if (strCell.equals("") || strCell == null) {
strCell = "";
}
return strCell.trim();
}