Phpexecel's own use records and phpexecel records

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.