How does thinkphp export a table in the excel format ------ solution ------------------ the front-end page is generated in the background, if you find the front-end SQL statement, you can use the original method to generate the corresponding excel example as follows: export de_once & nbsp; DB_connmssql.php; header (Content-T thinkphp how to export the table to excel format
How does thinkphp export a table in excel format?
------ Solution --------------------
The foreground page is generated in the background. if you find the SQL statement generated in the foreground, you can use the original method to generate the corresponding excel
Example:
Include_once 'DB _ connmssql. php ';
Header ("Content-Type: text/html; charset = utf-8 ");
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment; filename = tt -". date ('Y-m-D', time ()). ". xls "); // defines the generated file name
$ SQL = "xxx ";
$ Query = mssql_query ($ SQL _initbest );
$ X = 1;
While ($ row = mssql_fetch_array ($ query )){
If ($ x> = 1 ){
// Generate an excel column name
Echo iconv ("UTF-8", "gbk", 'Store code'). "\ t ";
//.....
Echo iconv ("UTF-8", "gbk", '% of total quantity sold'). "\ t ";
$ X --;
}
// $ Row ['store _ name'] = iconv ('gb2312', 'utf-8', $ row ['store _ name']); the table has Chinese characters that need to be processed like this
Echo "\ n ";
// Make a living
Echo iconv ("UTF-8", "gbk", $ row ['store _ number']). "\ t ";
//.....
Echo iconv ("UTF-8", "gbk", $ row ['other _ PS']). "\ t ";
}
?>
------ Solution --------------------
Try PHPExcel