导出excel部分代码

public static function header_file($doc,$file,$title,$type='Excel5'){  

       if(!empty($doc)){    

             $objWriter = self::writer_excel($doc,$title, $type);    //excel写入方法

             header("Content-Type: application/force-download");    

             header("Content-Type: application/octet-stream");   

             header("Content-Type: application/download");    

           //header("Content-Disposition: attachment; filename=".urlencode($file));                    

             $ua = $_SERVER["HTTP_USER_AGENT"];            

             $encoded_file = urlencode($file);            

             $encoded_file = str_replace("+", "%20", $encoded_file);            

            if (preg_match("/MSIE/", $ua)) {                

                   header('Content-Disposition: attachment; filename="' . $encoded_file . '"');            

           } else if (preg_match("/Firefox/", $ua)) {                

            header('Content-Disposition: attachment; filename*="utf8\'\'' . $file . '"');            

    } else {                

       header('Content-Disposition: attachment; filename="' . $file . '"');            

    }

      header("Content-Transfer-Encoding: binary");    

      header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    

      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');   

   }

  }

}

 

posted @ 2013-11-19 09:33  Echo正在输入  阅读(297)  评论(0)    收藏  举报