tinkphp execl乱符号化問題のエクスポート

17569 ワード

最近のプロジェクトでテストexeclのエクスポートに文字化けしの問題が発生し、資料を調べて以下のように整理した.
execlエクスポートコードクリップ:
    public function exportExcel($expTitle,$expCellName,$expTableData){
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);// 
        $fileName =  _.date('Ymd');//or $xlsTitle  
        $cellNum = count($expCellName);
        $dataNum = count($expTableData);
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new PHPExcel();
        $cellName = 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','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ'); 
        $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//  
        for($i=0;$i){
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i][1]); 
        } 
        for($i=0;$i){
          for($j=0;$j){
            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$expCellName[$j][0]]);
          }             
        }  
        
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment inline 
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  
        $objWriter->save('php://output'); 
        exit;   
    }
   function execlall(){// Excel
        parent::YanZheng('loginemails','__APP__/Index/renew');  // 
        $xlsName  = " ";
        $xlsCell  = array(
        array('Gaojing_jifang',' '),
        array('Gaojing_panduan',' '),
        array('Gaojing_equipment',' '),
        array('Gaojing_hpdate',' '), 
        array('Gaojing_log',' '),
        array('Gaojing_fenxi',' '),
        array('Gaojing_person',' '),
        array('Gaojing_date',' '),
        );
        $Person=new PersonModel();
        $condition1[$Person->_id]=session('loginemails');            // 
        $list1=$Person->where($condition1)->find();
        $condition["Gaojing_jifang"]=$list1["Person_bumen"];
        $xlsModel = new GaojingModel();
        $condition["Gaojing_panduan"]=$_GET['daochu'];
        
        ob_clean();   // 
if($_GET['daochu']=="all"){ $tiaojian["Gaojing_jifang"]=$list1["Person_bumen"]; $xlsData = $xlsModel->order('Gaojing_date desc')->where($tiaojian)->Field('Gaojing_jifang,Gaojing_panduan,Gaojing_equipment,Gaojing_hpdate,Gaojing_log,Gaojing_fenxi,Gaojing_person,Gaojing_date')->select(); $this->exportExcel($xlsName,$xlsCell,$xlsData); } $xlsData = $xlsModel->order('Gaojing_date desc')->where($condition)->Field('Gaojing_jifang,Gaojing_panduan,Gaojing_equipment,Gaojing_hpdate,Gaojing_log,Gaojing_fenxi,Gaojing_person,Gaojing_date')->select(); $this->exportExcel($xlsName,$xlsCell,$xlsData); }
 execlall ob_clean() , ;
 ob_clean  https://coderschool.cn/1963.html