Using table labels and PHP to output EXCEL

Source: Internet
Author: User
Tags php excel
The following describes the php excel output implementation code by using the table label. if you need a friend, refer to the following key code:
The code is as follows:
Header ("Content-type: application/vnd. ms-excel ");
Header ("Conten-Disposition: filename=hp.xlsx ");
?>

The first statement is used to declare the format of the file content; the second statement is used to modify the file name. If there is no second statement, the generated file will have no suffix.
Implementation code:
The code is as follows:

Header ("Content-type: application/vnd. ms-excel ");
Header ("Conten-Disposition: filename=hp.xlsx ");
?>



















I love you
No. Name Age
1 Test 20
2 Test2 22



Of course, we naturally thought about whether we can output the database content to a table in this way?
The answer is yes.
Implementation code:
The code is as follows:

Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: filename=qianshou.xls ");
Mysql_connect ("localhost", "root ","");
Mysql_select_db ("test ");
Mysql_query ("set names gbk ");
$ Query = "select * from city ";
$ R = mysql_query ($ query );
?>


















While ($ row = mysql_fetch_assoc ($ r )){?> }?>
City list
Id P_id Name


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.