Php outputs an excel file. If you want to use php to output excel files, you must use headercontent-type: applicationvnd. ms-excel. As follows? Php $ filenamename.. php Tutorial output excel format file
If you want to use php to output an excel file, you must use header content-type: application/vnd. ms-excel. As follows:
$ Filename = name .'.xls ';
Header ("content-type: application/vnd. ms-excel ");
Header ("content-disposition: attachment; filename = $ filename ");
?>
Let's look at the 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 data report", "gbk", $ page_code). ". xls ");
Header ("pragma: no-cache ");
Header ("expires: 0 ");
// $ Usersid = intval ($ _ get ['uid']); // user ID
// The output content is as follows:
// Output header
Echo iconv ("UTF-8", "gb2312", "customer name"). "t ";
Echo iconv ("UTF-8", "gb2312", "telephone"). "t ";
Echo iconv ("UTF-8", "gb2312", "address"). "t ";
Echo iconv ("UTF-8", "gb2312", "add Date"). "t ";
Echo "n"; // line feed
$ Sqlstr = "select * from clients where usersid = 32 order by clientsid desc ";
$ Rows = $ db-> select ($ sqlstr );
$ Num = count ($ rows); // total number of 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 feed
}
?>
Another simple instance
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 "second-level 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 ";
}
If you want to use php to output an excel file, you must use header content-type: application/vnd. ms-excel. As follows? Php $ filename = name .'....