Use header to export Excel garbled to find a stand

Source: Internet
Author: User
Using header to export Excel garbled and broken
This post was last edited by u014474944 on 2014-04-11 10:53:45

The code is as follows

Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachement;filename=khxx_". Date ("Ymd"). ". XLS ");
Include ("db.php");
$sql = "SELECT * from ' khxx '";
$query =mysql_query ($sql);
echo "The time \ t type \ t zone \ t name \ n address \ t contact phone \ t ID number \ t" \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "
while ($rs =mysql_fetch_array ($query)) {
echo "{$rs [' dates ']}\t{$rs [' type ']}\t{$rs [' area ']}\t{$rs [' names ']}\t{$rs [' Add ']}\t{$rs [' Phone ']}\t{$rs [' No ']}\t {$rs [' Set ']}\t{$rs [' dur ']}\t{$rs [' Give ']}\t{$rs [' Moneys ']}\t{$rs [' Attn ']}\t{$rs [' username ']}\t{$rs [' rem ']}\n ';
}
?>

------Solution--------------------
Are you excel2003?
Then you can only use the GBK character set
echo "The time \ t type \ t zone \ t name \ n address \ t contact phone \ t ID number \ t" \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "
Rewritten as
echo iconv (' Utf-8 ', ' GBK ', "time \ t type \ t zone \ t \ n" \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

$query =mysql_query ($sql);
Front Plus
mysql_query (' Set names GBK ');
  • 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.