(1) Environment configuration

Based on the environment

  • PHP7.4.4
  • MySQL8.0.19
  • Nginx1.16.1
  • System environment: Windows10 X64
  • PHP integration environment: phpEnv7.1.5 (www.phpenv.cn/)
  • Database management tool: Navicat Premium 15.0.11
  • PHP dependency management tool: Composer (getcomposer.org/Compo…)

(2) Install and configure ThinkPHP6.0

(1) Install ThinkPHP6.0

composer create-project topthink/think tp2excel
Copy the code

(2) Install Excel Spreadsheet plug-in

composer require phpoffice/phpspreadsheet
Copy the code

(3) Configure the site

(4) Configure Nginx rewrite

(5) Start and view the home page

(3) configuration database and database design

(1) Database configuration

(2) Database table construction (omitted)

(4) Query SQL data and export

(1) Introduce spread-php plug-in

(2) Query and export data

<? 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 "> export Excel < / a > < HTML > '; } public function excel($limit = 10) { $expTableData = Db::table('b_demo')->limit($limit)->select(); $fileName = "export IP address "; $Excel [' fileName '] = $fileName. The date (' d m Y year month day - 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; / / headlines, custom $Excel [' xlsCell] = [[' id ', 'id'], [' start ', 'began the IP], [' end', 'end IP'], [' disp ', 'area']]. Spread::excelPut($Excel,$expTableData); }}Copy the code

(3) Export the results

Original text: learnku.com/articles/42…