程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHPExcel 讀寫封裝類

PHPExcel 讀寫封裝類

編輯:關於PHP編程

  對於 excel  文件的的生成於數據讀取,我們可以用到 PHPExcel 插件。地址:http://phpexcel.codeplex.com/releases/view/107442 ,選第一個下載。然後解壓的文件目錄如下:

  初學者應該先去看示例,代碼不是很難理解。方法名都是觀其名,知其用。在看過些許例子的基礎上,我才想到封裝一下,用著方便。鑒於我自己也只是入門。所以寫了個相對入門的封裝。

 <form  method="post" enctype="multipart/form-data" >
 
 文件:<input type="file" name="files" /></li>
 <input type="submit" value="提交" />
 </form>
 
 <? 
 
 
  'Excel/Classes/PHPExcel.php' 
  myExcel      
             
      ; 
                 
               parent:: 
      
      
       
       setProperty(         ->objProperty = ->         (!(['creator']))->objProperty->setCreator(['creator'         (!(['title'])) ->objProperty->setTitle(['title'         (!(['subject']))->objProperty->setSubject(['subject'         (!(['laster']))->objProperty->setLastModifiedBy(['laster'         (!(['description']))->objProperty->setDescription(['description'         (!(['keyword']))->objProperty->setKeywords(['keyword'         (!(['category']))->objProperty->setCategory(['category'      
      
   
       addData(,  =           = ()? ->setActiveSheetIndex() : ->         (   =>              (() || ())              ->setCellValue(,        
     
       saveFile(,  = ,  = 'Excel5'         ->objWriter = PHPExcel_IOFactory::createWriter(,          
          = .         ->objWriter->save(      
 
     
     
       setReader(,  =          -> =          (             -> =              ->objReader = PHPExcel_IOFactory::createReader()->load(         }             -> = PHPExcel_IOFactory::identify(             ->objReader = PHPExcel_IOFactory::load(       
     
     
       loadFile(,  =          ->setReader(,          ->sheetData = ->objReader->getActiveSheet()->toArray(,,,      
     
       dataFormat(,  = 1,  =          (->sheetData   =>              ( &&  < )              ( &&  > )              (   =>                  ((,                      [][[]] =              (      
     
       sheetInfo( =          ()?  :  = ->          = ->objReader->listWorksheetInfo(                
  
 
 (  = './upImg/'  = .'aaa.xls' (!()) (, 0777, ) or ('上傳目錄創建失敗!'  = ['files']['tmp_name' (, );
 
  =          'title'=>'the title',
         'creator' => '作者'
   =          'A1'=>'a1111',
         'A2'=>'a222',
         'B1'=>'b111',
         'E1'=>'e111',
         'f2'=>'f22222'
  
  =  
         'g2'=>'f22222',
         'h1'=>'hhh',
         'j1'=>'jjjjj'
  
  =     
 
 ->loadFile('upImg/aaa.xls'  = ('A'=>'name','E'=>'age','F'=>'address'  = ->dataFormat(, , 5 (  ?>

 

數據返回的配置,可以看下圖:

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved