工作上业务近期上报数据使用的excel 之前都是Spoon 很少写poi 踩坑记录下
日期格式问题判断好类型直接通过 getDateCellValue() 即可正常格式存储
if (keyIndex.get("发证日期") != null) {//Java读取到为错误的日期格式 Value为天数 值为日期 月数为中文 无法处理
Cell licenseGrantDate = sheetRow.getCell(keyIndex.get("发证日期"));
if ("NUMERIC".equals(licenseGrantDate.getCellType().toString()) && isCellDateFormatted(licenseGrantDate)) {//判断cell类型是否为numeric number
ypLs.setLicenseGrantDate(licenseGrantDate.getDateCellValue());//直接set进 getDateValue 即可正常格式
} else { //cell的Type是正常的 直接正常解析即可
ypLs.setLicenseGrantDate(format.parse(String.valueOf(licenseGrantDate)));
}
}
数字格式 这里是手机号 存储后为 1******10E 这样的格式 解决方式如下
if (keyIndex.get("联系电话") != null) {
Cell phone = sheetRow.getCell(keyIndex.get("联系电话"));
phone.setCellType(CellType.STRING);
String stringCellValue = phone.getStringCellValue();
ypLs.setLinkPhone(stringCellValue);
}