Php simple excel output method (csv format) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags openid php excel
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...

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.