Home  >  Article  >  Backend Development  >  用header导出excel 乱码求立

用header导出excel 乱码求立

WBOY
WBOYOriginal
2016-06-13 11:54:37874browse

用header导出excel 乱码求破

本帖最后由 u014474944 于 2014-04-11 10:53:45 编辑 代码如下
<br /><?php<br />    header("Content-type:application/vnd.ms-excel");<br />    header("Content-Disposition:attachement;filename=khxx_".date("Ymd").".xls");<br />      include("db.php");<br />      $sql="SELECT * FROM `khxx`";<br />      $query=mysql_query($sql);<br />      echo "时间\t类型\t区域\t姓名\t具体地址\t联系电话\t证件号\t套餐\t时长\t赠送\t金额\t经办人\t帐号\t备注\n";<br />       while ($rs=mysql_fetch_array($query)){<br />        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";<br />            }<br />?><br />

------解决方案--------------------
你是 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');
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn