如何使用PHP将HTML内容保存并加载到文件中

时间:2022-09-04 08:06:37

I have a modal which contain table and have a save setup button and load setup button, When I click on save button the table content should be saved in a file in any folder in any format and by clicking on load button it should able to load that file in the HTML format.

我有一个包含表格的模态,并有一个保存设置按钮和加载设置按钮,当我点击保存按钮时,表格内容应保存在任何格式的任何文件夹中的文件中,并通过单击加载按钮,它应该能够加载HTML格式的文件。

So how can I do this?

那我该怎么做呢?

below is the code for Modal

下面是Modal的代码

<div class="modal fade" id="envVarModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel" style="text-align:center">Environment Variable Settings</h4>
      </div>
      <div class="modal-body" id="envVarModalBodyID">
        <label>Env Variable:</label>
        <select  id="envVarID" name="Select2" onchange="addEnvVar()">
            <option value="nothingSelected">Select Env Variable</option>
            <option value="Count">Count</option>
            <option value="Schedule">Schedule</option>

        </select>
        <table><tr><td>A</td><td>B</td></tr><tr><td>One</td><td>Two</td></tr><tr><td>Three</td><td>Four</td></tr></table>"
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Save Setup</button>
        <button type="button" class="btn btn-primary">Load Setup</button>
      </div>
    </div>
  </div>
</div>

1 个解决方案

#1


0  

Use this javascript to save the table in .xls format.I have added on click event to your button

使用此javascript以.xls格式保存表。我已将click事件添加到您的按钮

btn btn-default class where you have to make the table contain in <div id="table1">your table structure</div>

btn btn-default class,你必须使表包含在

你的表结构

<script>

    var tableToExcel = (function() {
      var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
        , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
      return function(table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
        window.location.href = uri + base64(format(template, ctx))
      }
    })()
    </script>



    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="tableToExcel('table1', 'W3C Example Table')" value="Export to Excel">

#1


0  

Use this javascript to save the table in .xls format.I have added on click event to your button

使用此javascript以.xls格式保存表。我已将click事件添加到您的按钮

btn btn-default class where you have to make the table contain in <div id="table1">your table structure</div>

btn btn-default class,你必须使表包含在

你的表结构

<script>

    var tableToExcel = (function() {
      var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
        , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
      return function(table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
        window.location.href = uri + base64(format(template, ctx))
      }
    })()
    </script>



    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="tableToExcel('table1', 'W3C Example Table')" value="Export to Excel">