Excel上传

public String doSend(){
  ArrayList <EmpEntity> list=new ArrayList<EmpEntity>();
  if(!"".equals(path)){
  try {
   System.out.println(path);
   //获取输入流
   InputStream input=new FileInputStream(path);
   //获取工作簿对象
   HSSFWorkbook wb = new HSSFWorkbook(input);
   //获取工作表
   HSSFSheet sheet=wb.getSheetAt(0);
   //获取工作表中的数据行数
   int count=sheet.getLastRowNum();
   //循环遍历数据表
   for(int i=1;i<=count;i++){
    //获取每行
    HSSFRow row=sheet.getRow(i);
    String id=row.getCell((short)0).getStringCellValue();
    String name=row.getCell((short)1).getStringCellValue();
    String sex=row.getCell((short)2).getStringCellValue();
    String deptName=row.getCell((short)3).getStringCellValue();
    String post=row.getCell((short)4).getStringCellValue();
    double balance=row.getCell((short)5).getNumericCellValue();
    int deptid=0;
    if("研发部".equals(deptName))
     deptid=21;
    else if("市场部".equals(deptName))
     deptid=22;
    else
     deptid=23;
    
    //转换拼音码
     String convert = "";
     for (int j = 0; j < name.length(); j++) {
      char word = name.charAt(j);
      // 提取汉字的首字母
      String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
      if (pinyinArray != null) {
       convert += pinyinArray[0].charAt(0);
      } else {
       convert += word;
      }
     }
  
    EmpEntity emp=new EmpEntity(id,name,sex,post,balance,deptid,convert);
    list.add(emp);
   }
   ServletActionContext.getRequest().getSession().setAttribute("empList",list);
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
  
  return "index";
  
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值