PHP Output Excel format file

Source: Internet
Author: User

If you want to use the PHP output Excel format file, you must use header Content-type:application/vnd.ms-excel to achieve. As follows

The code is as follows Copy Code
<?php
$filename = name. '. XLS ';
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename= $filename");
?>

And look at a PHP output Excel instance

The code is as follows Copy Code

<?php
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=test.xls");
echo "A1 B1 C1 A2 A3 A4";//r cell, New row
?>

The code is as follows Copy Code

<?php
Require_once (".. /.. /config/sys_config.php "); Configuration file
Require_once (".. /.. /include/db_class.php ");
Header ("content-type:text/html; charset= $page _code "); Page encoding
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename=". Mb_convert_encoding ("Customer Information Report", "GBK", $page _code). ". XLS ");
Header ("Pragma:no-cache");
Header ("expires:0");
$usersid = intval ($_get[' uid ')); User ID

The output reads as follows:
Output table Header
Echo iconv ("Utf-8", "gb2312", "Customer Name"). " ";
Echo iconv ("Utf-8", "gb2312", "Telephone"). " ";
Echo iconv ("Utf-8", "gb2312", "Address"). " ";
Echo iconv ("Utf-8", "gb2312", "Add Date"). " ";
echo ""; Line Wrap

$SQLSTR = "SELECT * from clients where usersid=32 order by clientsid Desc";
$rows = $db-> Select ($SQLSTR);
$num = count ($rows); Total Customers
for ($i = 0; $i < $num; $i + +)
{
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsname]). " ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsphone]). " ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsaddress]). " ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientstime]). " ";
echo ""; Line Wrap
}
?>


One more simple example

  code is as follows copy code

Header (" Content-type:application/vnd.ms-excel ");

Header ("Content-disposition:attachment;filename=users.xls");

Echo "Company name". T ";

Echo user name. T ";

echo "Password". T ";

echo "Level two domain name". T ";

echo "n";

foreach ($result [' result '] as $val) {

echo "$val->comname." T ";

echo "$val->username". T ";

echo "$val->usertruepw". T ";

Echo emptyempty ($val->domainname)? ':(' http://'. $val->domainname. Jiaomai.com '). " T ";

echo "n";

}

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.