Phpexecel's own use records and phpexecel records
$ User_ SQL = "select * from 'table '";
$ User_list = $ db-> fetchAll ($ user_ SQL); // Database Query
Require_once dirname (_ FILE _). '/.../../class/PHPExcel. php'; // load phpexcel. php and adjust it according to the path of your project.
$ ObjPHPExcel = new PHPExcel ();
$ ObjPHPExcel-> getProperties ()-> setCreator ("Maarten Balliauw ")
-> SetLastModifiedBy ("Maarten Balliauw ")
-> SetTitle ("Office 2007 XLSX Test Document ")
-> SetSubject ("Office 2007 XLSX Test Document ")
-> SetDescription ("Test document for Office 2007 XLSX, generated using PHP classes .")
-> SetKeywords ("office 2007 openxml php ")
-> SetCategory ("Test result file ");
// Set the title name
$ ObjPHPExcel-> setActiveSheetIndex (0)
-> SetCellValue ('a1', 'number ')
-> SetCellValue ('b1 ', 'Online Users ')
-> SetCellValue ('c1 ', 'cell phone ')
-> SetCellValue ('d1 ', 'record Time ');
// Loop every data. If you encounter data export from a mobile phone number, you can add a space before and after the corresponding data to convert the data into a string, execl is not displayed as a scientific data method.
Foreach ($ user_list as $ k => $ v ){
$ Num = $ k + 2;
$ ObjPHPExcel-> setActiveSheetIndex (0)
-> SetCellValue ('A'. $ num, $ v ['id'])
-> SetCellValue ('B'. $ num, $ v ['online'])
-> SetCellValue ('C'. $ num, ''. $ v ['phone _ num'].'')
-> SetCellValue ('D'. $ num, date ('Y-m-d h: I: s', $ v ['dateline ']);
}
$ ObjPHPExcel-> getActiveSheet ()-> getColumnDimension ('C')-> setWidth (20); // set the width of a column Cell
// Rename worksheet
$ ObjPHPExcel-> getActiveSheet ()-> setTitle ('sheet1 ');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$ ObjPHPExcel-> setActiveSheetIndex (0 );
$ Time_name = 'number of on-line persons '.date('ymdhis', time().'.xls '; // sets the default name of the file during download.
// Redirect output to a client's web browser (Excel5)
Header ('content-Type: application/vnd. ms-excel ');
Header ("Content-Disposition: attachment; filename = '$ time_name '");
Header ('cache-Control: max-age = 0 ');
// If you're serving to IE 9, then the following may be needed
Header ('cache-Control: max-age = 1 ');
// If you're serving to IE over SSL, then the following may be needed
Header ('expires: Mon, 26 Jul 1997 05:00:00 gmt'); // Date in the past
Header ('Last-Modified: '. gmdate ('d, d m y h: I: s'). 'gmt'); // always modified
Header ('cache-Control: Cache, must-revalidate'); // HTTP/1.1
Header ('pragma: public '); // HTTP/1.0
$ ObjWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5 ');
$ ObjWriter-> save ('php: // output ');
Die;