首页 >数据库 >mysql教程 >利用jxl把.xls文件导入到数据库

利用jxl把.xls文件导入到数据库

WBOY
WBOY原创
2016-06-07 15:36:081102浏览

Workbook wb = Workbook.getWorkbook(new File(E:\\lt.xls)); SimpleDateFormat df = new SimpleDateFormat(yyyyMMdd); Sheet sheet = wb.getSheet(0);// Cell cell = sheet.getCell(2,4); int hang = sheet.getRows(); int lie = sheet.getColumns(); ListH

<p>Workbook wb = Workbook.getWorkbook(new File("E:\\lt.xls"));
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); 
    Sheet sheet = wb.getSheet(0);
   
   // Cell cell = sheet.getCell(2,4);
    int hang = sheet.getRows();
    int lie = sheet.getColumns();
    List<Huadan> list = new ArrayList<Huadan>();
   
    for(int x=1;x<500;x++){
     
     
      String id = UUID.randomUUID().toString();
      Huadan huadan = new Huadan();
      huadan.setHdid(id);
      huadan.setThqsrq(df.parse(sheet.getCell(1, x).getContents()));
      System.out.println(df.parse(sheet.getCell(1, x).getContents()));
      
      huadan.setThqssj(sheet.getCell(2, x).getContents());
      System.out.println(sheet.getCell(2, x).getContents());
      
      huadan.setThsc(Integer.parseInt(sheet.getCell(3, x).getContents()));
      System.out.println(Integer.parseInt(sheet.getCell(3, x).getContents()));
      
      huadan.setHjlx(sheet.getCell(4, x).getContents());
      System.out.println(sheet.getCell(4, x).getContents());
      
      huadan.setMylx(sheet.getCell(5, x).getContents());
      System.out.println(sheet.getCell(5, x).getContents());
      
      huadan.setDfdqh(sheet.getCell(6, x).getContents());
      System.out.println(sheet.getCell(6, x).getContents());
      
      huadan.setDfhmq(sheet.getCell(7, x).getContents());
      System.out.println(sheet.getCell(7, x).getContents());
      
      huadan.setBjh(sheet.getCell(8, x).getContents());
      System.out.println(sheet.getCell(8, x).getContents());
      
      huadan.setThlx(sheet.getCell(9, x).getContents());
      System.out.println(sheet.getCell(9, x).getContents()+"dddddddd");
      
      huadan.setYsjbthf(Double.parseDouble(sheet.getCell(10, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(10, x).getContents()));
      
      huadan.setYhhjbthf(Double.parseDouble(sheet.getCell(11, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(11, x).getContents()));
      
      huadan.setYsctthf(Double.parseDouble(sheet.getCell(12, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(12, x).getContents()));
      
      huadan.setYhhctthf(Double.parseDouble(sheet.getCell(13, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(13, x).getContents()));
      
      huadan.setYsqtf(Double.parseDouble(sheet.getCell(14, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(14, x).getContents()));
      
      huadan.setYhh(Double.parseDouble(sheet.getCell(15, x).getContents()));
      System.out.println(Double.parseDouble(sheet.getCell(15, x).getContents()));
      
      huadan.setJzh(sheet.getCell(16, x).getContents());
      System.out.println(sheet.getCell(16, x).getContents());
      
      huadan.setXqh(sheet.getCell(17, x).getContents());
      System.out.println(sheet.getCell(17, x).getContents());
      
      huadan.setImei(sheet.getCell(18, x).getContents());
      System.out.println(sheet.getCell(18, x).getContents());
      
     
      System.out.println("----------------------------------------");
      list.add(huadan);
   
    }
    
    //System.out.println(hang+"  "+lie);
    wb.close();
  </p><p>   
    for(int x=0;x<list.size();x++){
     System.out.println(list.get(x).getThqssj()+"       ddddddd");
     this.shareDao.save(list.get(x));
    }
    </p>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn