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.