excel poi 批量导入源码

public String execute() throws Exception {
            //String  filename="C:\\Users\\Administrator\\Desktop\\副本tempexcel.xls";
            //FileInputStream file=new FileInputStream(filename);
            //System.out.println(file);
            HttpServletResponse response=null;
            response=ServletActionContext.getResponse();
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            
            
            POIFSFileSystem fs=new POIFSFileSystem(new  FileInputStream(stuUploadFile));
            HSSFWorkbook wb=new HSSFWorkbook(fs);
            HSSFSheet hssfSheet=wb.getSheetAt(0);
            
            if(hssfSheet!=null){
                for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){
                    HSSFRow hssfRow=hssfSheet.getRow(rowNum);
                    if(hssfRow==null){
                        continue;
                    }
                    StudentBean user=new StudentBean();
                    String a=ExcelUtil.formatCell(hssfRow.getCell(0));
                    String b=ExcelUtil.formatCell(hssfRow.getCell(1));
                    String c=ExcelUtil.formatCell(hssfRow.getCell(2));
                    String d=ExcelUtil.formatCell(hssfRow.getCell(3));
                    String e=ExcelUtil.formatCell(hssfRow.getCell(4));
                    String f=ExcelUtil.formatCell(hssfRow.getCell(5));
                    String g=ExcelUtil.formatCell(hssfRow.getCell(5));
                    user.setStudent_DomitoryID(Integer.parseInt(a.substring(0, a.indexOf("."))));
                    user.setStudent_Username(b.substring(0, b.indexOf(".")));
                    user.setStudent_Password(c.substring(0, c.indexOf(".")));
                    user.setStudent_Name(d);
                    user.setStudent_Sex(e);
                    user.setStudent_Class(f);
                    user.setStudent_State(g);
                    new StudentDao().Add(user);
                    
                }
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值