栺尖灬丿流年ヽ 发表于 2011-11-13 10:49:42

phpexcel 做导出数据时遇到乱码问题!!


<?php   if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Do_output extends CI_Controller {
   function __construct(){
   parent::__construct();
   header('Content-Type:text/html; charset=utf-8,gb2312');
            $this->load->library("phpexcel");
            $this->load->library("PHPExcel/iofactory");
               
    }
    function index(){
    }

    function outputExcel(){
       $objPHPExcel = new PHPExcel();//创建一个excel
       $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");   //2007以下的版本

          //到浏览器
          $outputFileName = date('Y_m_d').'.xls';
          $outputFileName = mb_convert_encoding($outputFileName, "gb2312", "UTF-8");

          header("Content-Type: application/force-download");
          header("Content-Type: application/octet-stream");
          header("Content-Type: application/download");
          header("Content-type:application/vnd.ms-excel");
          header('Content-Disposition:inline;filename="'.$outputFileName.'"');
          header("Content-Transfer-Encoding: binary");
          header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
          header("Pragma: no-cache");
          $objWriter->save("php://output");
          exit;
         }
}
      

这样不是会输出一个空的excel表格吗?为什么打开是乱码呢?
页: [1]
查看完整版本: phpexcel 做导出数据时遇到乱码问题!!