A simple method for php to output excel (csv format ). In php, you can use a professional excel processing class to add, delete, or process excel-related data. if you only want to generate an excel file, you can use the following method to make it simple and fast. For example, if you have a professional excel processing class in php, you can use it to add, delete, or process excel-related data. if you only want to generate an excel file, you can use the following simple and quick method.
If we do not read the data, we can use the following code directly. we only need to export the relevant data to an excel table. in this simple operation, we do not need to use the class libraries or anything. You can use the header directly: header ("Content-type: application/vnd. ms-excel ");
The code is as follows: |
|
Header ("Content-type: application/vnd. ms-excel "); Header ('content-Disposition: attachment=filename=policyingcai.xls "'); ?>
User name |
Password |
Admin |
Yingcai |
|
Simple and pure php excel sheet export method, with too many explanations and fancy decoration, can be understood at a glance
The code is as follows: |
|
Header ("Content-type: application/vnd. ms-excel "); Header ("Content-Disposition: attachment; filename ...xls "); Require_once ('./class. db. php '); $ Db = new DB ('localhost', 'app _ vmovies ', 'root', '123 '); $ SQL = 'select * from 'user' order by 'id' desc '; $ Ret = $ db-> get_results ($ SQL ); // The output content is 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 encoded, you also need to use the iconv function for transcoding, otherwise it will be garbled.
In addition, if the word format is similar, you can specify the header:
The code is as follows: |
|
Header ("Content-Type: application/msword "); Header ("Content-Disposition: attachment; filename=doc.doc "); |
Bytes. Such...