對於 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 ( ?>
數據返回的配置,可以看下圖: