在Excel导入时判断效验
2018-01-08 11:06
204 查看
1:excel有数据效验时 空值判断
/** * 检查表格数据是否为空 excel处理数据有效性 poi把空值当作shu * * @param obj * @return */ private boolean checkObjFieldIsNotNull(Object obj) { try { for (Field f : obj.getClass().getDeclaredFields()) { 4000 f.setAccessible(true); if (f.get(obj) != null) { return true; } } } catch (IllegalAccessException e) { } return false; }
/** * 调用这个方法,可以将空白行去掉: */ Iterator<excelus> it = excelList.iterator();//excelList是List<excelLine>类型的Excel数据,excelLine是行的数据类型 while(it.hasNext()){ if (isBlankObject(it.next())) { it.remove(); } }
/** * 用反射的方法可以排除这种数据 * @param model * @return * @throws NoSuchMethodException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException */ public static boolean isBlankObject(Object model) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ Field[] field = model.getClass().getDeclaredFields(); //获取实体类的所有属性,返回Field数组 for(int j=0 ; j<field.length ; j++){ //遍历所有属性 String name = field[j].getName(); //获取属性的名字 //System.out.println("attribute name:"+name); name = name.substring(0,1).toUpperCase()+name.substring(1); //将属性的首字符大写,方便构造get,set方法 //String type = field[j].getGenericType().toString(); //获取属性的类型 Method m = model.getClass().getMethod("get"+name); if(!StringUtils.isBlank((String)m.invoke(model))){ return false; } } return true; }
相关文章推荐
- Excel导入时 判断是否被占用
- poi导入excel判断单元格类型及转换
- Java导入Excel中的数据,及一些Excel的逻辑判断
- 使用反射,在Excel导入时判断是否有空行
- FH_1Excel报表导入,显示在JSP页面.人为判断后,不正确的数据生成PDF文档
- javaweb之动态读excel,导入excel,poi,jxl 支持判断2003.2007及以上
- java使用POI导入Excel,并判断合并单元格处,停止循环
- java中导入excel判断03还是07
- C# 中Excel导入时判断是否被占用三种方法
- 通过Navicat将Excel表中的数据导入到数据库
- 用Pl*SQL将Excel中数据导入到Oracle中
- txt、excel等导入数据的网址,未总结:
- 将excel数据通过plsql导入oracle的问题
- 少量数据通过Excel表格数据导入server SqlServer查询
- oracle 导入EXCEL数据的简单方法
- mvc4 强大的导出和不需要上传文件的批量导入EXCEL--SNF快速开发平台3.1
- Excel导入easyui dataGrid数据批量保存新思路
- java通过jxls框架实现导入导出excel
- [导入]判断键盘动作
- java实现将Excel表导入数据库