java中poi读取excel公式、函数计算值,返回无精度缺失的计算值
香蕉你个不呐呐ture:
大佬厉害,大佬救了我狗命,谢谢
[code=java]
case Cell.CELL_TYPE_FORMULA: {// 公式
try {
//判断cell是否为特殊日期格式,如果是得拦截-转换,否则会报错 xx-xx月-xxxx(类似于格式 : 01-一月-2022)
Pattern r = Pattern.compile("[\\d]{2}(-)([一二三四五六七八九十]{1,2}[月])(-)[\\d]{4}");
Matcher m = r.matcher(cell.toString());
if (m.find()) {
// System.out.println("奇怪格式时间分支");
cellValue = new SimpleDateFormat("yyyy/MM/dd").format(cell.getDateCellValue());
break;
}
//判断公式的类型,时间/数值/字符(报错时为字符)
if (DateUtil.isCellDateFormatted(cell)) {
// System.out.println("时间分支 -- now()");
cellValue = new SimpleDateFormat("yyyy/MM/dd").format(cell.getDateCellValue());
} else {
// Syste
[/code]
|