This article mainly introduces how to export Excel PHP, interested in a friend's reference, I hope to be helpful to everyone.
The code is as follows:
<?phperror_reporting (E_all);d ate_default_timezone_set (' Asia/shanghai '); require_once './Classes/PHPExcel.php ' ; $data =array (0=>array ' id ' =>1001, ' username ' and ' Zhang Fei ', ' password ' = ' 123456 ', ' address ' = ' and ' The Three Kingdoms ' Gao 250 Lane, Room 101 '), 1=>array (' id ' =>1002, ' username ' = ' Guan Yu ', ' password ' = ' 123456 ', ' address ' = ' + ' When the Three Kingdoms Huaguoshan '), 2=>array (' id ' =>1003, ' username ' = ' cao ', ' password ' = ' 123456 ', ' address ' = ' 2055 Lane 3rd Yanan West Road ' ), 3=>array (' id ' =>1004, ' username ' and ' Liu Bei ', ' password ' = ' 654321 ', ' Address ', ' No. 188th, ' Yu Yuan Road, Room 3309 ') ; $objPHPExcel =new Phpexcel (); $objPHPExcel->getproperties ()->setcreator (' http://www.jb51.net ')->set Lastmodifiedby (' http://www.jb51.net ')->settitle (' Office of XLSX Document ')->setsubje CT (' Office of XLSX document ')->setdescription (' Document for Office ' XLSX, generated using PHP clas Ses. ') ->setkeyworDS (' Office openxml php ')->setcategory (' Result file '); $objPHPExcel->setactivesheetindex (0)- >setcellvalue (' A1 ', ' ID ')->setcellvalue (' B1 ', ' username ')->setcellvalue (' C1 ', ' Password ')->setcellvalue (' D 1 ', ' address '); $i = 2; foreach ($data as $k = + $v) {$objPHPExcel->setactivesheetindex (0)->setcellvalue (' A '. $i, $v [' id '])->se Tcellvalue (' B '. $i, $v [' username '])->setcellvalue (' C ' $i, $v [' Password '])->setcellvalue (' D '. $i, $v [' Address ' ]); $i + +;} $objPHPExcel->getactivesheet ()->settitle (' Third grade 2 '); $objPHPExcel->setactivesheetindex (0); $filename = UrlEncode (' Student information tables '). ' _ '. Date (' Y-m-dhis '); Generate xlsx file/*header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet '); Header (' Content-disposition:attachment;filename= "'. $filename. '. Xlsx "'); header (' cache-control:max-age=0 '); $objWriter =phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel2007 ') ); *///generates the XLS file header (' Content-type:application/vnd.ms-exCel '); header (' Content-disposition:attachment;filename= '. $filename. XLS "'); header (' cache-control:max-age=0 '); $objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 '); $ Objwriter->save (' Php://output '); exit;
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP implementation of a simple probability method
The method and simple example of while loop control in PHP
How PHP implements cross-domain operations