If you do not read the data we directly use the following code, you need to export the relevant data to Excel table can be, such a simple operation does not need to use those class library or something. Directly with the header of the way can be:header ("Content-type:application/vnd.ms-excel");
The code is as follows |
Copy Code |
<?php Header ("Content-type:application/vnd.ms-excel"); Header (' Content-disposition:attachment;filename= "Yingcai.xls"); ?> <table border= "1″> <tr> <td> User name </td> <td> Password </td> </tr> <tr> <td>admin</td> <td>yingcai</td> </tr> </table> |
Simple and pure PHP export Excel table method, Wood has too much explanation, fancy decorations, a look at the understand
The code is as follows |
Copy Code |
Header ("Content-type:application/vnd.ms-excel"); Header ("content-disposition:attachment; Filename= User Information table. xls "); require_once ('./class.db.php '); $db = new db (' localhost ', ' app_vmovies ', ' root ', ' 123456 '); $sql = ' select * from ' user's ' ORDER BY ' ID ' desc '; $ret = $db->get_results ($sql); The //output reads as follows: echo "ID". T "; Echo "nickname". " T "; echo "Gender". T "; echo "OpenId". T "; echo "platform". T "; echo "Registration date." T "; echo "n"; $len = count ($ret); for ($i = 0; $i < $len; $i + +) { echo $ret [$i] [id]. " T "; echo $ret [$i] ["nickname"]. " T "; echo $ret [$i] ["gender"]. " T "; echo $ret [$i] [OpenID]. " T "; echo $ret [$i] [PF]. " T "; echo $ret [$i] ["RegDate"]. " T "; echo "n"; } |
If the program is Utf-8 code, also need to use the Iconv function to transcoding, otherwise it will be garbled, garbled.
Another word format import is similar, the header can be specified:
The code is as follows |
Copy Code |
Header ("Content-type:application/msword"); Header ("content-disposition:attachment; Filename=doc.doc "); |