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 ');