In PHP has a professional Excel processing class we can use it to add, delete or process the relevant data in Excel, if we just want to build Excel can use the following method is simple and fast.
If you do not read the data we can directly use the following code, just need to export the relevant data to Excel table, so simple operation will not need to use those class library or something. Directly with the header of the way you can: header ("Content-type:application/vnd.ms-excel");
The code is as follows |
Copy Code |
Header ("Content-type:application/vnd.ms-excel"); Header (' content-disposition:attachment;filename= ' Yingcai.xls "'); ?>
User name |
Password |
Admin |
Yingcai |
|
Simple and pure PHP export Excel table method, Wood has too much explanation, fancy decoration, a look on the understanding
code as follows |
copy code |
Header ("Content-type:application/vnd.ms-excel"); Header ("content-disposition:attachment; Filename= user Information Sheet. xls "); Require_once ('./class.db.php '); $db = new db (' localhost ', ' app_vmovies ', ' root ', ' 123456 '); $sql = ' select * ' from ' user ' 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 encoding, but also need to use the Iconv function to transcode, otherwise it will be garbled, garbled.
Another word format import is similar, you can specify the header:
The code is as follows |
Copy Code |
Header ("Content-type:application/msword"); Header ("content-disposition:attachment; Filename=doc.doc "); |
http://www.bkjia.com/PHPjc/632698.html www.bkjia.com true http://www.bkjia.com/PHPjc/632698.html techarticle in PHP has a professional Excel processing class we can use it to add, delete or process the relevant data in Excel, if we just want to build Excel can use the following method is simple and fast. Like ...