Java处理Excel导⼊将字段数据类型转换成String 使⽤Apache poi处理Excel,转换Excel字段类型为String⼯具类
public static String getCellValue(Cell cell){
String cellValue ="";
if(cell == null){
return cellValue;
}
// 判断数据的类型
CellType()){
case NUMERIC:// 数字
//short s = CellStyle().getDataFormat();
if(HSSFDateUtil.isCellDateFormatted(cell)){// 处理⽇期格式、时间格式
SimpleDateFormat sdf = null;
java valueof
// 验证short值
CellStyle().getDataFormat()==14){
sdf =new SimpleDateFormat("yyyy/MM/dd");
}else CellStyle().getDataFormat()==21){
sdf =new SimpleDateFormat("HH:mm:ss");
}else CellStyle().getDataFormat()==22){
sdf =new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
}else{
throw new RuntimeException("⽇期格式错误");
}
Date date = DateCellValue();
cellValue = sdf.format(date);
}else CellStyle().getDataFormat()==0){//处理数值格式
cell.setCellType(CellType.STRING);
cellValue = String.RichStringCellValue().getString());
}
break;
case STRING:// 字符串
cellValue = String.StringCellValue());
break;
case BOOLEAN:// Boolean
cellValue = String.BooleanCellValue());
break;
case FORMULA:// 公式
cellValue = String.CellFormula());
break;
case BLANK:// 空值
cellValue = null;
break;
case ERROR:// 故障
cellValue ="⾮法字符";
break;
default:
cellValue ="未知类型";
break;
}
return cellValue;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。