开发者

store and download the excel file in php

开发者 https://www.devze.com 2023-01-16 08:55 出处:网络
please check my coding for create the excel file and download. 开发者_如何学Cheader(\"Pragma: public\");

please check my coding for create the excel file and download.

  开发者_如何学C      header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");;
        header("Content-Disposition: attachment;filename=export.xls ");
        header("Content-Transfer-Encoding: binary ");

        echo "<table style='border: 1px solid red;border-color:red' cellspacing='0'>";
        echo "<tr>";
        echo "<th style='background-color:yellow;border:1px solid red'>Link id</th><th style='background-color:yellow;border:1px solid red'>Priority</th><th style='background-color:yellow;border:1px solid red'>Year</th><th style='background-color:yellow;border:1px solid red'>Make</th><th style='background-color:yellow;border:1px solid red'>Model</th><th style='background-color:yellow;border:1px solid red'>Input URL</th><th style='background-color:yellow;border:1px solid red'>Changes Found</th><th style='background-color:yellow;border:1px solid red'>Output filename</th><th style='background-color:yellow;border:1px solid red'>No of Changes</th>";
        echo "</tr>";
        echo "</table>";

thanks in advance


Use an external library like PHP Excel to create excel file and then send it to download. Is the easiest way and you don't have to reinvent the wheel. I've used this library and is very good. Alternately you think can use COM functions to do the same thing, although I never used them.


If you write an excelfile with an <table>, excel will send a warning to the user, trying to open the excel-file, that the file doesn't seem to be a regular file, and if they want to open it anyway.

http://i.stack.imgur.com/bx8ZY.png <- Image of the warning

0

精彩评论

暂无评论...
验证码 换一张
取 消