資源描述:
《PHP導(dǎo)入導(dǎo)出Excel方法》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、1:類Excel格式,這個其實不是傳統(tǒng)意義上的Excel文件,只是因為Excel的兼容能力強,能夠正確打開而已。修改這種文件后再保存,通常會提示你是否要轉(zhuǎn)換成Excel文件。優(yōu)點:簡單。缺點:難以生成格式,如果用來導(dǎo)入需要自己分別編寫相應(yīng)的程序。2:Excel格式,與類Excel相對應(yīng),這種方法生成的文件更接近于真正的Excel格式。如果導(dǎo)出中文時出現(xiàn)亂碼,可以嘗試將字符串轉(zhuǎn)換成gb2312,例如下面就把$yourStr從utf-8轉(zhuǎn)換成了gb2312:$yourStr=mb_convert_encoding(”gb2312″,“UTF-8″,$yourStr);
2、下面詳細列舉幾種方法。一、PHP導(dǎo)出ExcelPHP代碼
3、on.**Thislibraryisdistributedinthehopethatitwillbeuseful,*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU*LesserGeneralPublicLicenseformoredetails.**YoushouldhavereceivedacopyoftheGNULesserGeneralPublic*Licensealongwiththis
4、library;ifnot,writetotheFreeSoftware*Foundation,Inc.,51FranklinStreet,FifthFloor,Boston,MA02110-1301USA**@categoryPHPExcel*@packagePHPExcel*@copyrightCopyright(c)2006-2007PHPExcel)*@licenseLGPL*@version1.5.0,2007-10-23*//**Errorreporting*/error_reporting(E_ALL);/**Includepath**/set_in
5、clude_path(get_include_path().PATH_SEPARATOR.‘../Classes/’);/**PHPExcel*/include‘PHPExcel.php’;/**PHPExcel_Writer_Excel2007*/include‘PHPExcel/Writer/Excel2007.php’;//CreatenewPHPExcelobjectechodate(’H:i:s’).”CreatenewPHPExcelobject”;$objPHPExcel=newPHPExcel();//Setpropertiesechodate
6、(’H:i:s’).”Setproperties”;$objPHPExcel->getProperties()->setCreator(”MaartenBalliauw”);$objPHPExcel->getProperties()->setLastModifiedBy(”MaartenBalliauw”);$objPHPExcel->getProperties()->setTitle(”O(jiān)ffice2007XLSXTestDocument”);$objPHPExcel->getProperties()->setSubject(”O(jiān)ffice2007XLSXT
7、estDocument”);$objPHPExcel->getProperties()->setDescrīption(”TestdocumentforOffice2007XLSX,generatedusingPHPclasses.”);$objPHPExcel->getProperties()->setKeywords(”office2007openxmlphp”);$objPHPExcel->getProperties()->setCategory(”Testresultfile”);//Addsomedataechodate(’H:i:s’).”Addsom
8、edata