Excel export problem in IE

后端 未结 2 1083
[愿得一人]
[愿得一人] 2021-01-17 05:12

I have this script to export mysql data to excel. I have tried everything but I am not able to get this script to work for IE. The script downloads the data using FireFox or

相关标签:
2条回答
  • 2021-01-17 05:19

    Instead of outputting everything as a table, can you just output it as CSV, either manually formatting it, or something like implode('","', $row)? Leave the content-type header the way it is. I've had success doing that, even in IE.

    0 讨论(0)
  • 2021-01-17 05:43

    Headers

    Headers can be tricky with IE. Here's the thing, you should set it not to cache like this:

     ini_set('zlib.output_compression','Off');
            header('Pragma: public');
            header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");                  // Date in the past
            //header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
            header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
            header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
            header ("Pragma: no-cache");
            header("Expires: 0");
    

    Now there can be an issue with that if your server time is not set to the right timezone, this may actually have the opposite effect and force IE to cache it. Make sure your timezone is set for the correct timezone you are in. Is it a shared server? do you have ssh access??

    Excel Headers

    Now what you need is to provide the set of headers for IE

    header('Content-Transfer-Encoding: none');
            header('Content-Type: application/vnd.ms-excel;');                 // This should work for IE & Opera
            header("Content-type: application/x-msexcel");                    // This should work for the rest
            header('Content-Disposition: attachment; filename="'.basename($filename).'"');
    

    Try that, hopefully it should work.

    0 讨论(0)
提交回复
热议问题