您好,登錄后才能下訂單哦!
這篇文章主要介紹ThinkPHP6.0導(dǎo)出Excel的示例,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
(1)安裝ThinkPHP6.0
composer create-project topthink/think tp2excel
(2)安裝Excel插件phpspreadsheet
composer require phpoffice/phpspreadsheet
(3)配置站點(diǎn)
(4)配置Nginx重寫
(5)啟動,查看首頁
(1)數(shù)據(jù)庫配置
(2)數(shù)據(jù)庫建表(略)
(1)引入Spread.php插件
(2)查詢數(shù)據(jù)并導(dǎo)出
<?php namespace app\controller; use app\BaseController; use think\facade\Db; use Tools\Spread; class Index extends BaseController { public function index() { return '<html><a href="/index/excel.html?limit=2000">導(dǎo)出Excel</a><html>'; } public function excel($limit = 10) { $expTableData = Db::table('b_demo')->limit($limit)->select(); $fileName = "IP地址導(dǎo)出"; $Excel['fileName']=$fileName.date('Y年m月d日-His',time());//or $xlsTitle $Excel['cellName']=['A','B','C','D']; $Excel['H'] = ['A'=>12,'B'=>22,'C'=>28,'D'=>38];//橫向水平寬度 $Excel['V'] = ['1'=>40,'2'=>26];//縱向垂直高度 $Excel['sheetTitle']=$fileName;//大標(biāo)題,自定義 $Excel['xlsCell']=[ ['id','編號'], ['start','開始IP'], ['end','結(jié)束IP'], ['disp','地區(qū)']]; Spread::excelPut($Excel,$expTableData); } }
(3)導(dǎo)出結(jié)果
以上是“ThinkPHP6.0導(dǎo)出Excel的示例”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。