How does thinkphp export a table in excel format?

Source: Internet
Author: User
How does thinkphp export a table in the form of excel? the front-end page is generated in the background, if you find the SQL statement that generates the foreground, you can use the original method to generate the corresponding excel example as follows: paide_once & nbsp; 'DB _ connmssql. php '; header ("Conte thinkphp: How to export a table in 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

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.