Php-excel
tags (space delimited): PHP
Class Library: https://codeload.github.com/PHPOffice/PHPExcel/zip/1.8
Basic implementation of PHP export Excel tabular data
Implementation steps:
1 把文件夹放到extend目录下2 import助手函数导入类3 设置excel表头4 填充数据
Precautions:
1 数据从第二行开始填充
ThinkPHP5 Example:
# Common method Public Function Phpexcel ($title, $list, $fileName) {import (' PHPExcel.Classes.PHPExcel '); Import (' PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory '); $PHPExcel = new \phpexcel; $PHPSheet = $PHPExcel->getactivesheet (); foreach ($list as $k + $v) {# code ... foreach ($title as $key + = $value) {if ($k = = 0) { $PHPSheet->setcellvalue ($key. ' 1 ', End ($value)); } $i = $k + 2; $PHPSheet->setcellvalue ($key. $i, $v [Reset ($value)]); }} $PHPWriter = \phpexcel_iofactory::createwriter ($PHPExcel, "Excel2007"); Header ("Pragma:public"); Header ("expires:0"); Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0"); Header ("Content-type:application/force-download"); Header ("Content-type:application/vnd.ms-execl"); Header ("Content-type:application/octet-stream"); Header ("Content-type:application/download");; Header (' Content-disposition:attachmenT;filename= '. $fileName. Xlsx '); Header ("Content-transfer-encoding:binary"); $PHPWriter->save ("Php://output");} # Call Method: Public Function Main () {$title = [' A ' = = = ' id ', ' id '], ' B ' = = [' nickname ', ' nickname '], ' C ' = = [' Phone ', ' mobile number '], ' D ' = [' Avatar ', ' Avatar '], ' E ' + = [' profile ', ' personal signature '], ' F ' = [' Toke n ', ' user uniquely identified '], ' G ' = = [' Sex ', ' gender '], ' H ' = = ' [' Status ', ' state '], ' I ' = [' to_host ', ' Organizer ID '] ]; $field = ' id, nickname, phone, Avatar, profile, token, sex, status, To_host '; $list = db::table (' T_user ')->field ($field)->limit ()->select (); $fileName = ' Test '. Date (' y-m-d '); $this->excel ($title, $list, $fileName);}
Thinkphp5-phpexcel Export Data