Phpexcel is a powerful Excel export/import plug-in, it can even export PDFs, etc., is a very useful PHP plug-ins, PHP learning is essential. So how do you use it, here's the Phpexcel entry paradigm:
PHP Source Reference:
<?php
Require_once ("phpexcel/phpexcel.php");
$excel = new Phpexcel (); Instantiate the Phpexcel class
Set author (not necessary)
$excel->getproperties ()->setcreator ("Reson");
The following is the data to be exported
$datas = Array (
Array
0 => ' UID ',
1 => ' username ',
2 => ' sex '
),
Array
0 => ' 1 ',
1 => ' Reson ',
2 => ' Men '
),
Array
0 => ' 2 ',
1 => ' Anyse ',
2 => ' female '
)
);
Start exporting. Note that $i starts at 1 and cannot start at 0 for the following reasons: ' A '. $i, when I=1 is A1 (first row, first lattice)
$i = 1;
foreach ($datas as $key => $val) {
$excel->getactivesheet ()->setcellvalue (' A '. $i, $val [' 0 ']);
$excel->getactivesheet ()->setcellvalue (' B '. $i, $val [' 1 ']);
$excel->getactivesheet ()->setcellvalue (' C '. $i, $val [' 2 ']);
$i + +;
}
$excel->getactivesheet ()->settitle (' PHP learner list '); meaning See the following figure
$fileName = ' Test ';
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. ') XLS "');
Header ("Content-transfer-encoding:binary");
$objWriter = Phpexcel_iofactory::createwriter ($excel, ' Excel5 ');
$objWriter->save (' php://output ');
?>
This is the way it is, is it very easy to use it?