用的PHPExcel 下载出现乱码的问题
发布网友
发布时间:2022-04-06 03:52
我来回答
共4个回答
热心网友
时间:2022-04-06 05:21
编码问题,解决方法:
一、开头加上一句:
header("Content-Type:text/html;charset=GB2312");
同时把你页面中的“ $cellvalue=iconv("gbk","UTF-8",$content...”的utf-8也统一为GB2312试试!
二、也可改用下面办法,不用$Excelobj=new PHPExcel();对象,而是直接输出html格式(只是把扩展名改为.xsl),因为excel,word本身是很好的html编辑器,能直接解释html标签:
//如果是xsl,word等则更简单,只需直接在原来的php文件开头加上下面几句:
<?php
header("Content-Type: application/force-download");//提示下载,而不是直接打开!
if( $sExport == "excel"){
header("ContentType = application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$oTitle.".xls");
}
if( $sExport == "word"){
echo ("<div align='center'><font size=+2>收文登记簿</font><hr size=3 align='center' width=360></div><br>");
header("ContentType = application/vnd.ms-word");//或试试 application/msword
header("Content-Disposition: attachment; filename=".$oTitle.".doc");
}
if( $sExport == "csv"){
header("ContentType = application/csv"); //图像image/jpeg",或image/*"
header("Content-Disposition: attachment; filename=".$oTitle.".csv");
}
//.....输出原来的php代码
热心网友
时间:2022-04-06 06:39
<?php
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "3721";
$DB_DBName = "wangshang";
$DB_TBLName = "ws_info";
$savename = date("YmjHis");
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect.");
mysql_query("Set Names gb2312"); $file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type;charset=big5");
header("Content-Disposition: attachment; filename=".$savename.".$file_ending");
//header("Pragma: no-cache");
$now_date = date("Y-m-j H:i:s");
$title = "数据库名:$DB_DBName,数据表:$DB_TBLName,备份日期:$now_date";
$time='1303776000';
echo date("Y-m-d",$time);
$sql = "Select ws_type,info2,info1,tel,mobile,userid from $DB_TBLName where cityid='7' and addtime>'".$time."'and ws_type='2'";
echo $sql;
exit;
$ALT_Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database");
$result = @mysql_query($sql,$Connect) or die(mysql_error());
echo("$title\n");
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++){
echo mysql_field_name($result,$i)."\t";
}
print("\n");
$i = 0;
while($row = mysql_fetch_row($result)){
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++){
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
$i++;
}
return (true);
?>
直接用就可以了
热心网友
时间:2022-04-06 08:14
下载后 文件打开 需要进行格式转换!
全部转换为 UTF-8
热心网友
时间:2022-04-06 10:05
是你的浏览器 错码而已
全部转换为 UTF-8