1. Download Phpexcel
2. Introduce the Phpexcel class file to the page and create the object of the class
include (".. /chajian/phpexcel/classes/phpexcel.php "); $excel New Phpexcel ();
3. Query the database to get a two-dimensional array here the array is named: $attr
4. Export Excel code, table header array and data array corresponding to:
//Excel table format, where 10 columns are briefly written$letter=Array(' A ', ' B ', ' C ', ' D ', ' E ', ' f ', ' f ', ' G ', ' H ', ' I ');//Table Header Array$tableheader=Array(' Reporting time ', ' reporting complete ', ' reporting staff ', ' final accomplishment ', ' tutor reviews ');//Populating header information for($i= 0;$i<Count($tableheader);$i++) {$excel->getactivesheet ()->setcellvalue ("$letter[$i]1 ","$tableheader[$i]");}//Populating table Information for($i= 2;$i<=Count($attr) + 1;$i++) {$j= 0;foreach($attr[$i-2] as $key=$value) {$excel->getactivesheet ()->setcellvalue ("$letter[$j]$i","$value");$j++;}}//Create an Excel input object$write=NewPhpexcel_writer_excel5 ($excel);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= ' {$SJ}_{$BT} job. xls ' ");Header("Content-transfer-encoding:binary");$write->save (' php://output ');
5. If the long digit string is displayed as a scientific counting solution
(1) Specify the type of data to display when setting the value
$excel->getactivesheet ()->setcellvalueexplicit (' D1 ', 120000000000,phpexcel_cell_datatype::type_ STRING);
(2) Add a space before the numeric string to make it a string
$excel->getactivesheet ()->setcellvalue (' D1 ', '. 120000000000);
Phpexcel Exporting data tables