Home > Backend Development > PHP Tutorial > php关于phpexcel乱码问题

php关于phpexcel乱码问题

WBOY
Release: 2016-06-20 12:41:51
Original
1126 people have browsed it

导出excel文件  出现了一个问题 在导出行数5行以上的时候 导出数据格式正常  在5行一下数据的时候 中文全部乱码  这个问题请教各位大神  代码贴出来下面
$filename='exceptionOrder'.date('Y-m-d');
        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Content-type:application/vnd.ms-excel;charset=UTF-8");
        header("Content-Disposition:attachment;filename=".$filename.".xls");
        header("Pragma: no-cache");
        header("Expires: 0");
        $table = '';
        $table.='

'.PHP_EOL;
        $table.='
            
            
            

            
            
            
            '.PHP_EOL;
$i = 1;
        foreach($data as $key =>$val){
if($val['orders_warehouse_id']==1000){
$str =  "深圳一仓";
}else if($val['orders_warehouse_id']==1025){
$str =  "义乌仓";
  }
        $table.='
                     

                     
                     '.PHP_EOL;
$i++;    //序号自增
        }
        $table.='
序号'.iconv("gb2312","UTF-8",'序号').' SKU 仓库 库位 实库存
'.$i.' '.$val['product_sku'].' '.$str.' '.$val['products_location'].' '.$val['actual_stock'].'
'.PHP_EOL;
        echo $table;


回复讨论(解决方案)

没看到在哪里用了 phpexcel

转下码就行了

楼上两位都不对   请看清问题



应该是你数据库出来的时候已经有问题了

fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 添加 BOM

如果导出csv格式的话,在WPS上都正常,就是在MS office上会乱码。加上这个就正常了。我也是最近才知道的。

$table  = pack("C3",239,187,191);

试下行不。为啥你用html格式展示呢,我通常是用csv格式,让文件下载的。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template