gpt4 book ai didi

javascript - 如何使用javascript将HTML用户输入数据存储到excel中

转载 作者:行者123 更新时间:2023-11-30 16:43:34 26 4
gpt4 key购买 nike

我需要使用 JavaScript 创建 HTML 页面,它可以将用户信息直接存储到 excel 中。信息可以包含用户输入字段,例如:

  1. 名字(数据类型:文本)
  2. 姓氏(数据类型:文本)

我已尝试使用以下代码将值存储到 CSV 中,但我不知道如何将值存储到 Excel 工作表中。

<hrml>
<head>
<script language="javascript">
function WriteToFile(passForm) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileLoc = "D:\\sample.csv";
var file = fso.OpenTextFile(fileLoc, 8, true,0);
file.writeline(passForm.FirstName.value + ',' +
passForm.LastName.value);
file.Close();
alert('File created successfully at location: ' + fileLoc);
}

</script>
</head>
<body>
<p>create a csv file with following details -</p>
<form>
Type your first name: <input type="text" name="FirstName" size="20">
Type your last name: <input type="text" name="LastName" size="20">
<input type="button" value="submit" onclick="WriteToFile(this.form)">
</form>
</body>
</html>

请帮我解决“如何使用 JavaScript 将 HTML 输入数据写入 Excel”

非常感谢您。

最佳答案

您可以在 JavaScript 代码中使用 ActiveXObject() 创建自动化对象(在 Windows 中)。示例:

var ExcelApp = new ActiveXObject("Excel.Application");
var ExcelSheet = new ActiveXObject("Excel.Sheet");
// a text is stored in the first cell
ExcelSheet.ActiveSheet.Cells(1,1).Value = "Texto1";
// the sheet is saved
ExcelSheet.SaveAs("D:\\TEST.XLS");
// close Excel with the Quit() method of the Application object
ExcelSheet.Application.Quit();

关于javascript - 如何使用javascript将HTML用户输入数据存储到excel中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31564756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com