基于POI的Excel导入工具

导入Excel一直都是信息系统的一项基本功能,它让用户的录入工做变得轻松快捷,然而,对于程序员来讲,为了实现这一功能却须要花不少的精力去实现,若是Excel的表格字段够多,那确定够你忙的了! 
下面这个工具能帮助你轻松方便灵活的帮你实现Excel导入的功能。它是我本身使用过程当中总结完成的,请高手多指正! 
jar文件里面包含有java源代码! 


标签: POI  Excel

代码片断(2)


[代码] [Java]代码

01         Excel2EntityConfig config = new Excel2EntityConfig();
02         String[] columns = {"name""password""birthday"};
03         config.setColumns(columns);
04 //      //设置日期的格式,和Excel里的日期格式一至
05 //      config
06 //              .setFormater(new SimpleDateFormat(
07 //                      "yyyy.MM.dd"));
08 //      //设置从第行开始读,忽略前4行
09 //      config.setCurrPosittion(5);
10 //      //设置从第二列开始读取,忽略第一列的数序号列
11 //      config.setColStartPosittion(2);
12         ExcelReader<TestEntity> excel = new ExcelReader<TestEntity>();
13         excel.setExcel2EntityConfig(config);
14          
15         File file = new File("d:\\testEntity.xls"); //把testEntity.xls文件复制到d:
16         InputStream input = new FileInputStream(file); 
17         //若是现现EXCEl编码问题引发的读取问题,请将InputStream换成 ByteArrayInputStream 可解决问题
18         //ByteArrayInputStream input = new ByteArrayInputStream(byte[])
19         excel.InitExcelReader(input);
20         try {
21             TestEntity entity = new TestEntity();
22             excel.setEntity(entity);
23             entity = excel.readLine();
24              
25             while (entity != null) {               
26                 System.out.print(entity.getName()+" ");
27                 System.out.print(entity.getPassword()+" ");
28                 System.out.println(entity.getBirthday().toLocaleString());
29                 ///保存实体代码
30                 entity = new TestEntity();
31                 excel.setEntity(entity);
32                 entity = excel.readLine();
33             }
34         catch (IOException e) {
35             e.printStackTrace();
36         catch (Exception e) {
37             e.printStackTrace();
38         finally{
39             input.close();

40         }      
下载地址: http://www.oschina.net/code/snippet_103544_6721
相关文章
相关标签/搜索