StevenBot-Saltsam

眼睛能装下世界,为何却装不下眼泪? 一只风筝一辈子只为一根线冒险。 那不是一场游戏,为何总有一根线牵着心怀,隐隐作疼? 那不是一段邂逅,为何飘在桥上的影子,总缠进梦乡? 那不是一个梦境,为何你的温柔私语,总是不经意的响起?

导航

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

datas link

OSChinal Sources codes Library

搜索

最新评论

阅读排行榜

评论排行榜

将Excel文件内容写入到数据库

 public   class  EStudentInsertExcelController  extends  SimpleFormController  {

     private  IStudent_infoManage studentManage;

    @Override
     protected  ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
             throws  Exception  {
        Student_info student_info  =  (Student_info) command;
         try   {            
            MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;
            MultipartFile file  =  multipartRequest.getFile( " Excelfile " );  //  获得文件: 
 
            File toFile  =   new  File( " c:\\学生信息临时文件.xls " ); //  产生文件名和空文件 
 
            file.transferTo(toFile); //  文件上传 
 
            Workbook book  =  Workbook.getWorkbook(toFile); // 得到工作薄             
 
            Sheet sheet  =  book.getSheet( 0 ); //  获得第一个工作表对象 
 
             int  row  =  sheet.getRows(); //  /得到该sheet的行数 
 
             int  column  =  sheet.getColumns();  //  得到该sheet的列数     
 
            System.out.println( " 数据行数= " + row);
            System.out.println( " 数据列数= " + column);
             for ( int  i = 1 ;i < row;i ++ )
             {
                 for ( int  j = 0 ;j < column;j ++ )
                 {
                    System.out.println( " j= " + j);
                    sheet.getCell(j, i).getContents(); //  得到第j列第i行的单元格的类容         
 
                    student_info.setStudentID(sheet.getCell(j, i).getContents());    
                    student_info.setName(sheet.getCell( ++ j,i).getContents());    
                    student_info.setSex(sheet.getCell( ++ j,i).getContents());    
                    student_info.setUnit(sheet.getCell( ++ j,i).getContents());    
                    student_info.setClass_(sheet.getCell( ++ j,i).getContents());    
                    student_info.setSpecialty(sheet.getCell( ++ j,i).getContents());    
                    student_info.setRemark(sheet.getCell( ++ j,i).getContents());                        
                } 
    
                 if  ( this .studentManage.getStudentByStudentID(
                        student_info.getStudentID()).size()  !=   0 )
                     return   new  ModelAndView( " education/e-studentInfoAddError " );
                 this .studentManage.insertStudent_info(student_info);    
            } 
                
            book.close();
             return   new  ModelAndView( " education/e-studentInfoAddExcelSuccess " , " row " , new  Integer(row - 1 ));
        } 
  catch  (Exception e)  {                    
            e.printStackTrace();
        } 

         return   new  ModelAndView( " education/e-studentInfoAddExcelError " );
    } 

 
      public   void  setStudentManage(IStudent_infoManage studentManage)  {
         this .studentManage  =  studentManage;
    } 
    

posted on 2011-11-16 14:12 Steven_bot 阅读(329) 评论(0)  编辑  收藏 所属分类: tools


只有注册用户登录后才能发表评论。


网站导航: