1 private static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2
3 /**
4 * 获取单元格的值
5 *
6 * @param cell
7 * @return
8 */
9 public static String getCellValue(Cell cell) {
10 DecimalFormat df = new DecimalFormat("#");
11 if (cell == null)
12 return "";
13
14 if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
15 return cell.getStringCellValue();
16 } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
17 return String.valueOf(cell.getBooleanCellValue());
18 } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
19 return cell.getCellFormula();
20 } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
21 if (HSSFDateUtil.isCellDateFormatted(cell)) { //判断是日期类型
22 Date dt = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());//获取成DATE类型
23 return dateformat.format(dt);
24 }else{ //转化电话号码和身份证号码为字符串
25 return String.valueOf(df.format(cell.getNumericCellValue()));
26 }
27
28
29
30 }
31 return "";
32 }