cwkzhy

 *万能处理方案

所有日期格式都可以通过getDataFormat()值来判断

yyyy-MM-dd----- 14

yyyy年m月d日--- 31

yyyy年m月------- 57

m月d日  ---------- 58

HH:mm----------- 20

h时mm分  ------- 32

 

Java代码  收藏代码
  1. //1、判断是否是数值格式  
  2. if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){  
  3.     short format = cell.getCellStyle().getDataFormat();  
  4.     SimpleDateFormat sdf = null;  
  5.     if(format == 14 || format == 31 || format == 57 || format == 58){  
  6.         //日期  
  7.         sdf = new SimpleDateFormat("yyyy-MM-dd");  
  8.     }else if (format == 20 || format == 32) {  
  9.         //时间  
  10.         sdf = new SimpleDateFormat("HH:mm");  
  11.     }  
  12.     double value = cell.getNumericCellValue();  
  13.     Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value);  
  14.     result = sdf.format(date);  
  15. }  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-29
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2021-12-08
  • 2021-12-13
  • 2022-12-23
  • 2022-03-06
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案