用header匯出excel 亂碼求立

來源:互聯網
上載者:User
用header匯出excel 亂碼求破
本帖最後由 u014474944 於 2014-04-11 10:53:45 編輯

代碼如下

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 "時間\t類型\t地區\t姓名\t具體地址\t聯絡電話\t證件號\t套餐\t時間長度\t贈送\t金額\t經辦人\t帳號\t備忘\n";
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";
}
?>

------解決方案--------------------
你是 excel2003 ?
那麼你只能使用 gbk 字元集
echo "時間\t類型\t地區\t姓名\t具體地址\t聯絡電話\t證件號\t套餐\t時間長度\t贈送\t金額\t經辦人\t帳號\t備忘\n";
改寫為
echo iconv('utf-8', 'gbk', "時間\t類型\t地區\t姓名\t具體地址\t聯絡電話\t證件號\t套餐\t時間長度\t贈送\t金額\t經辦人\t帳號\t備忘\n");

$query=mysql_query($sql);
前面加上
mysql_query('set names gbk');
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.