下面由thinkphp框架教程栏目给大家分享一个ThinkPHP6.0 导出 Excel 案例 ,希望对需要的朋友有所帮助!
(1)安装ThinkPHP6.0
composer create-project topthink/think tp2excel
(2)安装Excel插件phpspreadsheet
composer require phpoffice/phpspreadsheet
(3)配置站点
(4)配置Nginx重写
(5)启动,查看首页
(1)数据库配置
(2)数据库建表(略)
(1)引入Spread.php插件
(2)查询数据并导出
<?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)导出结果
以上是【分享案例】ThinkPHP6.0 导出 Excel的详细内容。更多信息请关注PHP中文网其他相关文章!