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 );
?>
City list |
Id |
P_id |
Name |
While ($ row = mysql_fetch_assoc ($ r )){?>
|
|
|
}?>