jxl 实现excel导入

 /**   * 导入Excel数据   *   * @param file   * @return   * @throws FileNotFoundException   * @throws SQLException   * @throws BiffException   */  public void insertXslInfo(FormFile file) throws FileNotFoundException,    SQLException {

  jxl.Workbook wb = null;   // sql语句list   List insertList = new ArrayList();   UserListDao dao = new UserListDao();   try {    wb = Workbook.getWorkbook(file.getInputStream());   } catch (BiffException e) {    e.printStackTrace();   } catch (IOException e) {    // TODO Auto-generated catch block    e.printStackTrace();   } // 得到工作薄   jxl.Sheet st = wb.getSheet(0);// 得到工作薄中的第一个工作表   Cell cell = st.getCell(0, 0);// 得到工作表的第一个单元格,即A1   String content = cell.getContents();// getContents()将Cell中的字符转为字符串   // 得到行数   int rowCount = st.getRows();

  for (int i = 1; i < rowCount; i++) {    // 用户信息bean    UserBean userbean = new UserBean();    // 得到某一行的单元格    Cell[] ce = st.getRow(i); // jxl.Cell[] ce= st.getRow(i);    String rowno = ce[0].getContents().toString();    // 用户编号    String userno = ce[1].getContents().toString();    userbean.setUserno(userno);    // 用户姓名    String username = ce[2].getContents().toString();    userbean.setUsername(username);    // 性别    String sex = ce[3].getContents().toString();     userbean.setSex(sex);     // 出生日期    String birth = ce[4].getContents().toString();     userbean.setBirthday(birth);           // 创建时间    String createtime = ce[5].getContents().toString();     userbean.setCreatetime(createtime);          // 照片    String image = ce[6].getContents().toString();    userbean.setImage(image);    insertList.add(i - 1, userbean);   }   try {    dao.insXls(insertList);   } catch (SQLException e) {    // TODO Auto-generated catch block    e.printStackTrace();    throw e;   }  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值