PHP Excel Header

后端 未结 4 702
迷失自我
迷失自我 2020-12-06 01:13
header(\"Content-Type:   application/vnd.ms-excel; charset=utf-8\");
header(\"Content-type:   application/x-msexcel; charset=utf-8\");
header(\"Content-Disposition:          


        
相关标签:
4条回答
  • 2020-12-06 01:34

    The problem is you typed the wrong file extension for excel file. you used .xsl instead of xls.

    I know i came in late but it can help future readers of this post.

    0 讨论(0)
  • 2020-12-06 01:37

    Try this

    header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    header("Content-Disposition: attachment;filename=\"filename.xlsx\"");
    header("Cache-Control: max-age=0");
    
    0 讨论(0)
  • 2020-12-06 01:48

    Just try to add exit; at the end of your PHP script.

    0 讨论(0)
  • 2020-12-06 01:50

    You are giving multiple Content-Type headers. application/vnd.ms-excel is enough.

    And there are couple of syntax error too. To statement termination with ; on the echo statement and wrong filename extension.

    header("Content-Type:   application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=abc.xls");  //File name extension was wrong
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    echo "Some Text"; //no ending ; here
    
    0 讨论(0)
提交回复
热议问题