欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php导出excel再IE下乱码问题

程序员文章站 2022-07-26 11:44:26
$userBrowser = $_SERVER['HTTP_USER_AGENT']; //判断是否是ie内核 $fileName = '会员列表-'.date('Y-m-d', time()).'.xls'; if( preg_match( '/MSIE/i', $userBrowser ) ) ... ......
         $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');