參考網址:https://neohsuxoops.blogspot.com/2020/09/phpspreadsheetphpexcel-xoops.html
PHPExcel,但是官網已經說明PHPExcel套件因升級不易只能支援到php5.6,該物件已於2017年正式棄用,並於2019年永久歸檔,換句話說PHPExcel套件對於日後新版的excel格式均不支援,為保持程式在最新狀態只好棄用PHPExcel改使用PhpSpreadsheet電子表格套件
唯一比較麻煩的是使用PhpSpreadsheet要先佈署composer,如果沒佈署composer是沒辦法使用的,還好官方有釋出已經設定好的phpoffice套件可以直接引入使用,省了很多麻煩,請直接參考「參考網站」
官方網站:https://github.com/PHPOffice
點下資訊社的教學
https://campus-xoops.tn.edu.tw/modules/tad_book3/page.php?tbsn=36&tbdsn=1336
套用樣板
好處是不用全部都用程式來寫,可以自己設定好各種花俏的格式,程式只負責把值填上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php require 'vendor/autoload.php' ; $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load( 'test.xlsx' ); $worksheet = $spreadsheet ->getActiveSheet(); $worksheet ->getCell( 'A1' )->setValue( '套用樣板測試' ); header( 'Content-Type: application/vnd.ms-excel' ); header( 'Content-Disposition: attachment;filename="套用樣板測試.xls"' ); header( 'Cache-Control: max-age=0' ); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $spreadsheet , 'Xls' ); $writer ->save( 'php://output' ); |