StevenBot-Saltsam

          眼睛能裝下世界,為何卻裝不下眼淚? 一只風箏一輩子只為一根線冒險。 那不是一場游戲,為何總有一根線牽著心懷,隱隱作疼? 那不是一段邂逅,為何飄在橋上的影子,總纏進夢鄉? 那不是一個夢境,為何你的溫柔私語,總是不經意的響起?

          導航

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          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 閱讀(349) 評論(0)  編輯  收藏 所屬分類: tools


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 湟中县| 锡林郭勒盟| 阳春市| 湘乡市| 嘉荫县| 会泽县| 长春市| 江门市| 铜梁县| 壶关县| 营口市| 泰州市| 金门县| 荥经县| 临漳县| 工布江达县| 故城县| 灵武市| 普兰县| 广饶县| 邯郸市| 施秉县| 清新县| 凉城县| 裕民县| 长汀县| 宁武县| 西峡县| 芷江| 江西省| 咸阳市| 沁水县| 邹平县| 康乐县| 安平县| 依安县| 都昌县| 乳山市| 营山县| 江油市| 郧西县|