Two native php excel File Export methods (recommended ),

Source: Internet
Author: User

Two native php excel File Export methods (recommended ),

Method 1:

$ Filename = 'file name'; $ filetitle = 'your title'; if ($ _ POST) {set_time_limit (10000); $ title = ''; ini_set ('memory _ limit ', '300m'); header ('content-Type: application/vnd. ms-excel; charset = UTF-8 '); $ name = $ title. ". xls "; header ('content-Disposition: attachment; filename = '. $ name. ''); header ('cache-Control: max-age = 0'); $ where =" 1 = 1 "; $ SQL =" "; $ query = DB :: query ($ SQL); // php file handle. php: // output indicates that the file is directly output to the browser $ fp = fopen ('php: // output', 'A '); // output the Excel column header information $ head = array ('id'); // Replace the character $ p_new_lines = array ("\ r \ n", "\ n ", "\ t", "\ r", "\ r \ n", "<pre>", "</pre>", "<br> ", "</br>", "<br/>"); $ p_change_line_in_excel_cell = ''; foreach ($ head as $ v) {echo iconv ('utf-8 ', 'gb2312', $ v ). "\ t" ;}echo "\ n"; // counter $ cnt = 0; // refresh the output buffer at every $ limit row to save resources $ limit = 100000; // extract data row by row to save memory while ($ res = mysql_fetch_assoc ($ query) {$ cnt ++; if ($ limit = $ cnt) {// refresh the output buffer to prevent problems caused by excessive data. ob_flush (); flush (); $ cnt = 0;} echo trim ($ res ['id']). "\ t"; echo "\ n ";}}

Method 2:

$ Filename = 'file name'; $ filetitle = 'your title'; if ($ _ POST) {$ title = ''; ini_set ('memory _ limit ', '300m'); header ('content-Type: application/vnd. ms-excel; charset = UTF-8 '); $ name = $ title. ". xls "; header ('content-Disposition: attachment; filename = '. $ name. ''); header ('cache-Control: max-age = 0'); echo '

The above two methods (recommended) for exporting excel files from php native are all the content shared by the editor. I hope you can give us a reference and hope you can provide more support.

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.