基础环境
(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 appcontroller; use appBaseController; use thinkfacadeDb; use ToolsSpread; 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)导出结果
原文:https://learnku.com/articles/42212
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!