奇怪的字符导出到Excel时

嗨即时通讯使用下一个代码在PHP导出到Excel。 其实它很好..但我总是得到奇怪的字符? (UTF8)

我发现加..

Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.Default; 

将解决我的问题..

但我无法设法把它放在这里,我总是得到500服务器错误。

这是我的代码

 //insertamos los headers que van a generar el archivo excel header('Content-type: application/vnd.ms-excel'); //en filename vamos a colocar el nombre con el que el archivo xls sera generado header("Content-Disposition: attachment; filename=ventas.xls"); header("Pragma: no-cache"); header("Expires: 0"); //hacemos la conexion al servidor MySql $dbhost = "xxx"; $dbuser = "xxx"; $dbpass = "xxx"; $dbname = "xxx"; $conexio = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to database"); mysql_select_db($dbname); //realizamos la consulta $tableName="usuarios"; $sql = mysql_query("SELECT id,name,lastname,email,codigo, media, phone, Pcode, birth FROM $tableName",$conexio); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Reporte de ventas</title> </head> <body><!–Vamos a crear una tabla que será impresa en el archivo excel –> <table width="600" border="0"> <tr> <th width="600"> <!-–Imprimimos un titulo -–> <div style="color:#003; text-align:center; text-shadow:#666;"><font size="+2">Reporte de Ventas <br />Usuarios</font></div></th> </tr> </table> <!–-creamos la tabla de el reporte con border 1 y los títulos-–> <table width="641" border="1"> <tr> <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Ventas</strong></th> <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Fecha</strong></th> </tr> <?php // Un proceso repetitivo para imprimir cada uno de los registros. while($row = mysql_fetch_array($sql)){ echo " <tr> <td bgcolor=\"#ededed\" align=\"center\">{$row['name']}</td> <td bgcolor=\"#ededed\" align=\"center\">{$row['email']}</td> </tr>"; } 

好的,我find了答案..

需要应用mb_convert_encoding

 while($row = mysql_fetch_array($sql)){ foreach($row as &$value) { $value = mb_convert_encoding($value, "UTF-8", "Windows-1252"); } 

并为我使用的标题

 header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-type: application/x-msexcel; charset=utf-8"); header("Content-Disposition: attachment; filename=ventas.xls"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); 

只是把它放在Excel :: create之前

ob_clean();