yangzailu

导航

php导出excel再IE下乱码问题

         $userBrowser = $_SERVER['HTTP_USER_AGENT']; //判断是否是ie内核
            $fileName = '会员列表-'.date('Y-m-d', time()).'.xls';
            if( preg_match( '/MSIE/i', $userBrowser ) ) {
                $fileName = urlencode($fileName);
            }else{
                $fileName = iconv('UTF-8', 'GBK//IGNORE', $fileName);
            }

            header('pragma:public');
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename='.$fileName.'');  //日期为文件名后缀
            header('Cache-Control: max-age=0');
                
            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  //excel5为xls格式,excel2007为xlsx格式
            $objWriter->save('php://output');

 

posted on 2018-05-29 18:11  飞离地平线  阅读(351)  评论(0编辑  收藏  举报