The following describes the implementation code of using phpexcel to export data in php. if you need to use phpexcel, you can refer to the following code.
The code is as follows:
Public function export_data ($ data = array ())
{
# Code...
Include_once (APP_PATH. 'tools/PHPExcel/Classes/PHPExcel/Writer/IWriter. php ');
Include_once (APP_PATH. 'tools/PHPExcel/Classes/PHPExcel/Writer/excel5.php ');
Include_once (APP_PATH. 'tools/PHPExcel/Classes/PHPExcel. php ');
Include_once (APP_PATH. 'tools/PHPExcel/Classes/PHPExcel/IOFactory. php ');
$ Obj_phpexcel = new PHPExcel ();
$ Obj_phpexcel-> getActiveSheet ()-> setCellValue ('A1', 'key ');
$ Obj_phpexcel-> getActiveSheet ()-> setCellValue ('b1 ', 'value ');
If ($ data ){
$ I = 2;
Foreach ($ data as $ key => $ value ){
# Code...
$ Obj_phpexcel-> getActiveSheet ()-> setCellValue ('A'. $ I, $ value );
$ I ++;
}
}
$ Obj_Writer = PHPExcel_IOFactory: createWriter ($ obj_phpexcel, 'excel5 ');
$ Filename = "outexcel.xls ";
Header ("Content-Type: application/force-download ");
Header ("Content-Type: application/octet-stream ");
Header ("Content-Type: application/download ");
Header ('content-Disposition: inline; filename = "'. $ filename .'"');
Header ("Content-Transfer-Encoding: binary ");
Header ("Last-Modified:". gmdate ("D, d m y h: I: s"). "GMT ");
Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
Header ("Pragma: no-cache ");
$ Obj_Writer-> save ('php: // output ');
}