如何基于HTML表创建Excel文件并将其保存在项目目录

时间:2016-08-18 07:47:27

标签: javascript php jquery excel html5

我已经构建了一个HTML表并在其中加载数据。我想要做的是,根据包含数据的表创建(或转换)它excel并将excel文件保存在项目目录中。

这是我的HTML表格

 <table class='tblNemoList' border='1' cellpadding='3' cellspacing='0' width='100%' style='-fs-table-paginate: paginate;'>
            $thChanges
            $trChanges
            $thMissing
            $trMissing
            $thNew
            $trNew
         </table>
      ";
      $strFilename = "FIM_KnowMore_Report_$DT";

excel转换就在这里

header("Pragma: no-cache");
      header("Expires: 0");
      header("Content-type: application/x-msdownload");
      header("Content-Disposition: attachment; filename=". $strFilename .".xls"); //gets set inside the report.rpt.php
      file_put_contents($strFilename, $strBody);

我错过了将其保存在目录中的代码。你能帮忙吗?

1 个答案:

答案 0 :(得分:1)

PHPExcel是一个很棒的库,用于使用php创建和处理excel文件。 试一试。

PHPExcel on GitHub