首页 > 其他 > 详细

easypoi导出Excel遇到的坑

时间:2020-01-15 12:05:02      阅读:688      评论:0      收藏:0      [点我收藏+]

当对象属性名称第二个字母为大写时会导致导出对应属性数据为空情况。

举例:public String aBTest;

导致对应属性导出为空的原因:

easypoi在处理属性时判断不够全面,使用时需要注意

判断逻辑:

(
name.length() == 1 || name.length() > 1 && !Character.isUpperCase(name.charAt(1))
)
出现问题的具体方法见下面代码:
PoiReflectorUtil.class
private static String methodToProperty(String name) {
if (name.startsWith("is")) {
name = name.substring(2);
} else {
if (!name.startsWith("get") && !name.startsWith("set")) {
throw new RuntimeException("Error parsing property name ‘" + name + "‘. Didn‘t start with ‘is‘, ‘get‘ or ‘set‘.");
}

name = name.substring(3);
}

if (name.length() == 1 || name.length() > 1 && !Character.isUpperCase(name.charAt(1))) {
name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
}

return name;
}

easypoi导出Excel遇到的坑

原文:https://www.cnblogs.com/rgyfred/p/12195426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!