使用javascript在excel fom html表中写

时间:2015-08-12 12:28:10

标签: javascript html

我想获取html表值并将其写入excel。 获取表的值以进行查询。 这是我用样式表写的html表:

<body>
  <div>
    <table id="table" border="2" style="top:230px">
    <tr>
      <td width="200" height="150">
        <xsl:value-of select="agu2a_nb"></xsl:value-of>
      </td>
      <td width="200" height="150">
        <xsl:value-of select="pdm_ecn_type"></xsl:value-of>
      </td>
      <td width="200" height="150">
        <xsl:value-of select="pdm_project_code"></xsl:value-of>
      </td>
      <td width="300" height="150">
        <xsl:value-of select="created_by_id/@keyed_name"></xsl:value-of>
      </td>
      <td width="200" height="150">
        <xsl:value-of select="created_on"></xsl:value-of>
      </td>
      <td width="200" height="150">
        <xsl:value-of select="state"></xsl:value-of>
      </td>
    </tr>
    </table>
  </div>
</body>

我想在预定义的Excel中编写此表。 有人可以建议如何继续。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用JavaScript将数据存储在文件中是不可能的,因为JavaScript是一种客户端语言,无法访问文件系统(可能导致安全问题), 但你可以使用JavaScript获取数据,然后将其发送到服务器端脚本(php,asp等)来处理它。

这是一个简单的例子:

<body>
  <div>
      <table id="table" border="2" style="top:230px">
          <tr>
                      <td width="200" height="150">
                          <input type="text" id="agu2a_nb">
                      </td>
                     <td width="200" height="150">
                         <input type="text" id="pdm_ecn_type">
                      </td>
                      <td width="200" height="150">
                          <input type="text" id="pdm_project_code">
                      </td>
                      <td width="300" height="150">
                         <input type="text" id="created_by_id">
                      </td>
                      <td width="200" height="150">
                         <input type="text" id="created_on">
                      </td>
                     <td width="200" height="150">
                         <input type="text" id="state">
                      </td>
               </tr>
          </table>

      <input type="submit" id="send" value="send">


      <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> 
      <script>
        $(document).ready(function(){
          var obj {};

            $('#send').click(function(){
                obj.agu2a_nb = $('#agu2a_nb').val(),
                obj.pdm_ecn_type = $('#pdm_ecn_type').val(),
                obj.pdm_project_code = $('#pdm_project_code').val(),
                obj.created_by_id = $('#created_by_id').val(),
                obj.created_on = $('#created_on').val(),
                obj.state = $('#state').val();

            });

          $.post('server_side_url',obj,function(response_returned_from_sever){

          });


        });
      </script> 
  </div>
</body>