<pre name="code" class="java">private String getValue(Cell cell) {
if (cell.getCellType() == cell.CELL_TYPE_BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == cell.CELL_TYPE_NUMERIC) {
String cellValue = "";
if (HSSFDateUtil.isCellDateFormatted(cell)) { //判断是日期类型
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");
Date dt = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());//获取成DATE类型
cellValue = dateformat.format(dt);
}else{
DecimalFormat df = new DecimalFormat("0");
cellValue = df.format(cell.getNumericCellValue());
}
return cellValue;
} else {
return String.valueOf(cell.getStringCellValue());
}
}
POI读取excel日期显示为数字的解决办法
最新推荐文章于 2022-08-18 16:18:14 发布