如何将数据从HTML保存到excel中,点击表单上的“提交”button?

<form> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <input type="submit" value="Submit"> </form> 

我想点击“提交”它应该保存在Excel工作表的名字和姓氏。 我不想使用数据库,我没有任何服务器。 我读了一个地方,我们可以在CSV中做同样的事情。 帮帮我。

提前致谢。

一个可能的方法是创build一个HTML表格。 您可以将表单值设置为不可见表格,并通过链接模拟html表格的下载。 Excel读取html并显示数据。


例如:

 function exportF() { //Format your table with form data document.getElementById("input").innerHTML = document.getElementById("text").value; var table = document.getElementById("table"); var html = table.outerHTML; var url = 'data:application/vnd.ms-excel,' + escape(html); // Set your html table into url var link = document.getElementById("downloadLink"); link.setAttribute("href", url); link.setAttribute("download", "export.xls"); // Choose the file name link.click(); // Download your excel file return false; } 
 <form onsubmit="return exportF()"> <input id="text" type="text" /> <input type="submit" /> </form> <table id="table" style="display: none"> <tr> <td id="input"> </td> </tr> </table> <a style="display: none" id="downloadLink"></a> 

有许多库允许生成.xlsx文件,您需要select其中一个(Google xlsx.js ),在提交时读出表单中的值,然后使用您select的库创build想要的电子表格。