Home > Article > PHP Framework > [Share Case] ThinkPHP6.0 Export to Excel
Below, the thinkphp framework tutorial column will share with you a ThinkPHP6.0 export Excel case. I hope it will be helpful to friends in need!
(1) Install ThinkPHP6.0
composer create-project topthink/think tp2excel
(2) ) Install the Excel plug-in phpspreadsheet
composer require phpoffice/phpspreadsheet
(3) Configure the site
(4) Configure Nginx rewrite
(5) Start and view the homepage
(1) Database configuration
(2) Database table creation (omitted)
(1 ) Introduce the Spread.php plug-in
(2) Query data and export
<?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">导出Excel</a><html>'; } public function excel($limit = 10) { $expTableData = Db::table('b_demo')->limit($limit)->select(); $fileName = "IP地址导出"; $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;//大标题,自定义 $Excel['xlsCell']=[ ['id','编号'], ['start','开始IP'], ['end','结束IP'], ['disp','地区']]; Spread::excelPut($Excel,$expTableData); } }
(3) Export the results
The above is the detailed content of [Share Case] ThinkPHP6.0 Export to Excel. For more information, please follow other related articles on the PHP Chinese website!