<?php
//header("Content-type:application/vnd.ms-excel");
header("Content-type: application/vnd.ms-excel;charset=utf-8");
header("Content-Disposition: attachment; filename=users.xls");
$conn=mysql_connect('localhost','root','sanzhixiong') or die('err');
mysql_select_db('dom') or die ('is err');
mysql_query("SET NAMES 'utf8'");
$sql="select * from renwu";
$query=mysql_query($sql);
$tx='';
echo $tx."\n\n";
echo "负责人"."\t";
echo "课程名"."\t";
echo "栏目"."\t";
echo "点数"."\t\n";
while($row=mysql_fetch_array($query))
{
echo $row['fuzeren']."\t";
echo $row['kecheng']."\t";
echo $row['lanmu']."\t";
echo $row['dianshu']."\t\n";
}
?>
我把数据里面的数据打印出来显示在网页上是可以显示中文的,但是生成excel的时候就会出现乱码,求教我三个都是utf8,但是还有乱码,希望高手指点一下
//header("Content-type:application/vnd.ms-excel");
header("Content-type: application/vnd.ms-excel;charset=utf-8");
header("Content-Disposition: attachment; filename=users.xls");
$conn=mysql_connect('localhost','root','sanzhixiong') or die('err');
mysql_select_db('dom') or die ('is err');
mysql_query("SET NAMES 'utf8'");
$sql="select * from renwu";
$query=mysql_query($sql);
$tx='';
echo $tx."\n\n";
echo "负责人"."\t";
echo "课程名"."\t";
echo "栏目"."\t";
echo "点数"."\t\n";
while($row=mysql_fetch_array($query))
{
echo $row['fuzeren']."\t";
echo $row['kecheng']."\t";
echo $row['lanmu']."\t";
echo $row['dianshu']."\t\n";
}
?>
我把数据里面的数据打印出来显示在网页上是可以显示中文的,但是生成excel的时候就会出现乱码,求教我三个都是utf8,但是还有乱码,希望高手指点一下
如果你想在excel中显示出结果,,可以考虑将所有的字段,包括前面的 “负责人”“栏目”等,都用
iconv('utf-8', 'gbk', $str);转换了
mysql_query("SET NAMES 'utf8'");这两处换成gbk即可