PHP tutorial output Excel format file
If you want to take advantage of the PHP output Excel format file, you must use the header Content-type:application/vnd.ms-excel to achieve. As follows
$filename = name. XLS ';
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename= $filename");
?>
Look at one more PHP output Excel instance
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=test.xls");
echo "A1tb1tc1tna2ta3ta4tn";//r T cell, n new row
?>
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 Profile 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"). " T ";
Echo iconv ("Utf-8", "gb2312", "Phone"). " T ";
Echo iconv ("Utf-8", "gb2312", "Address"). " T ";
Echo iconv ("Utf-8", "gb2312", "Add Date"). " T ";
echo "n"; Line break
$SQLSTR = "SELECT * from clients where usersid=32 order by clientsid Desc";
$rows = Select $db, $sqlstr);
$num = count ($rows); Total Customers
for ($i = 0; $i < $num; $i + +)
{
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsname]). " T ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsphone]). " T ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientsaddress]). " T ";
Echo iconv ("Utf-8", "gb2312", $rows [$i][clientstime]). " T ";
echo "n"; Line break
}
?>
One more simple example
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";
}
http://www.bkjia.com/PHPjc/630800.html www.bkjia.com true http://www.bkjia.com/PHPjc/630800.html techarticle PHP Tutorial Output Excel format file if you want to take advantage of PHP output Excel format files, you must use the header Content-type:application/vnd.ms-excel to achieve. The following PHP $filename = name. ' ....