PHP Output Excel Simple method (CSV format) _php tutorial

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

  • 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.