Excel2EntityConfig config = new Excel2EntityConfig(); String[] columns = {"name", "password", "birthday"}; config.setColumns(columns); // //设置日期的格式,和Excel里的日期格式一至 // config // .setFormater(new SimpleDateFormat( // "yyyy.MM.dd")); // //设置从第行开始读,忽略前4行 // config.setCurrPosittion(5); // //设置从第二列开始读取,忽略第一列的数序号列 // config.setColStartPosittion(2); ExcelReader<TestEntity> excel = new ExcelReader<TestEntity>(); excel.setExcel2EntityConfig(config); File file = new File("d:\\testEntity.xls"); //把testEntity.xls文件复制到d: InputStream input = new FileInputStream(file); //如果现现EXCEl编码问题引起的读取问题,请将InputStream换成 ByteArrayInputStream 可解决问题 //ByteArrayInputStream input = new ByteArrayInputStream(byte[]) excel.InitExcelReader(input); try { TestEntity entity = new TestEntity(); excel.setEntity(entity); entity = excel.readLine(); while (entity != null) { System.out.print(entity.getName()+" "); System.out.print(entity.getPassword()+" "); System.out.println(entity.getBirthday().toLocaleString()); ///保存实体代码 entity = new TestEntity(); excel.setEntity(entity); entity = excel.readLine(); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally{ input.close(); }
开源中国-程序员在线工具:Git代码托管 API文档大全(120+) JS在线编辑演示 二维码 更多»
引用来自“刘灿文”的评论
很好的,可以用,谢谢分享
引用来自“谭明智”的评论
引用来自“杨哲沣”的评论
引用来自“谭明智”的评论
引用来自“陈雨霖”的评论
引用来自“谭明智”的评论
引用来自“莫坏人”的评论
里面有个小bug 下了包打包源码运行,其中读取数据是不完全的。主要是for循环哪儿。