用的PHPExcel 下载出现乱码的问题 100

/*header("Content-type:text/csv");header("Pragma:public");header("Expires:0");header(... /*
header("Content-type: text/csv");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Disposition:attachment;filename="' . 'simple' . '.xlsx"');
header("Content-Transfer-Encoding:binary");
*/
include 'include/Classes/PHPExcel.php';
include 'include/Classes/PHPExcel/Writer/Excel2007.php';

public function execute($titles,$contents,$feilds)
{
$Excelobj=new PHPExcel();

$Excelobj->getProperties()->setCreator("Maarten Balliauw");
$Excelobj->getProperties()->setLastModifiedBy("Maarten Balliauw");
$Excelobj->getProperties()->setTitle("Office 2007 XLSX Test Document");
$Excelobj->getProperties()->setSubject("Office 2007 XLSX Test Document");
$Excelobj->getProperties()->setKeywords("office 2007 openxml php");
$Excelobj->getProperties()->setCategory("Test result file");

$words=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$rowindex=1;
$columncount=count($titles);
$Excelobj->setActiveSheetIndex(0);
for($i=0;$i<$columncount;$i++)
{
$cellname=$words[$i].$rowindex;
$cellvalue=iconv("gbk","UTF-8",$titles[$i]);
$Excelobj->getActiveSheet()->setCellValue($cellname, $cellvalue);
}
foreach($contents as $content)
{
$rowindex++;
for($i=0;$i<$columncount;$i++)
{
$cellname=$words[$i].$rowindex;
$cellvalue=iconv("gbk","UTF-8",$content["$feilds[$i]"]);
$Excelobj->getActiveSheet()->setCellValue("$cellname", "$cellvalue");
}
}
$Excelobj->getActiveSheet()->setTitle(iconv("gbk","UTF-8",'simple'));
$Excelobj->setActiveSheetIndex(0);
$objWriter = new PHPExcel_Writer_Excel2007($Excelobj);
$objWriter->save('php://output');
}
在网上查了查 可是问题还是没有解决 现在把 $objWriter->save('php://output'); 中的svae地址换成“E://”就没什么问题 求个完整的正解 望有经历的不吝赐教
展开
 我来答
遒劲还谦逊灬标兵1
2011-05-03 · TA获得超过1207个赞
知道小有建树答主
回答量:431
采纳率:100%
帮助的人:156万
展开全部
编码问题,解决方法:
一、开头加上一句:
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代码
yylongren
2011-05-05 · TA获得超过283个赞
知道小有建树答主
回答量:366
采纳率:75%
帮助的人:69.2万
展开全部
<?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);
?>
直接用就可以了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Finish1983
2011-05-03 · TA获得超过762个赞
知道小有建树答主
回答量:1477
采纳率:100%
帮助的人:396万
展开全部
下载后 文件打开 需要进行格式转换!

全部转换为 UTF-8
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wudipaopao
2011-05-04 · TA获得超过797个赞
知道小有建树答主
回答量:1486
采纳率:0%
帮助的人:804万
展开全部
是你的浏览器 错码而已
全部转换为 UTF-8
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式