如何使用html在Excel工作表中保存登录数据?

如何使用html在Excel工作表中保存登录数据?,html,excel,vbscript,Html,Excel,Vbscript,我需要什么 我需要在excel工作表中保存登录数据,同时用户单击html中的提交按钮 还是我做的 使用vb脚本我已经做到了这一点 错误 子示例()未定义的脚本错误 数据不保存 对话框没有响应 子样本() 调试器; 黯淡 设置objExcel=CreateObject(“Excel.Application”) 设置objWorkbook=objExcel.Workbooks.Open(“E:\excel\work.xlsx”) 'Document.GetElementsByName

我需要什么

  • 我需要在excel工作表中保存登录数据,同时用户单击html中的提交按钮
还是我做的

  • 使用vb脚本我已经做到了这一点
错误

  • 子示例()未定义的脚本错误
  • 数据不保存
  • 对话框没有响应


子样本()
调试器;
黯淡
设置objExcel=CreateObject(“Excel.Application”)
设置objWorkbook=objExcel.Workbooks.Open(“E:\excel\work.xlsx”)
'Document.GetElementsByName(“fname”)(0.Value=“C#”
'Document.GetElementsByName(“lname”)(0.Value=“Corner”
'Document.GetElementsByName(“Add1”)(0.Value=“Tamilnadu”
'Document.GetElementsByName(“Add2”)(0.Value=“Coimbatore”
objExcel.Application.Visible=True
objWorkbook.Windows(1).Visible=True
set XlSheet=objWorkbook.Sheets(1)
激活
iRow=1
用objExcel
执行While.Cells(iRow,1).value“”
.单元格(iRow,1)。激活
iRow=iRow+1
环
.Cells(iRow,1).value=Document.GetElementsByName(“fname”)(0).value
.Cells(iRow,2).value=Document.GetElementsByName(“lname”)(0).value
.Cells(iRow,3).value=Document.GetElementsByName(“Add1”)(0).value
.Cells(iRow,4).value=Document.GetElementsByName(“Add2”)(0).value
MsgBox“数据添加成功”,vbinformation
Document.GetElementsByName(“fname”)(0.Value=“”
Document.GetElementsByName(“lname”)(0.Value=“”
Document.GetElementsByName(“Add1”)(0.Value=“”
Document.GetElementsByName(“Add2”)(0.Value=“”
以
objWorkbook.save
objWorkbook.close
设置objWorkbook=Nothing
设置objExcel=Nothing
端接头
字段集{
边框:#00cc00 2px实心;
填充:10px;
颜色:绿色;

你能用JavaScript代替vb脚本吗?是的,但是没有得到正确的结果,请分享你的代码
<!DOCTYPE html>
<html>
<head>
<script language="vbscript" type="text/vbscript">
Sub Sample()
debugger;
Dim iRow
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("E:\excel\work.xlsx")
'Document.GetElementsByName("fname")(0).Value="C#"
'Document.GetElementsByName("lname")(0).Value="Corner"
'Document.GetElementsByName("Add1")(0).Value="Tamilnadu"
'Document.GetElementsByName("Add2")(0).Value="Coimbatore"
objExcel.Application.Visible = True
objWorkbook.Windows(1).Visible = True
set XlSheet =objWorkbook.Sheets(1)
XlSheet.Activate
iRow = 1
With objExcel
Do While .Cells(iRow, 1).value <> ""
.Cells(iRow, 1).activate
iRow = iRow + 1
Loop
.Cells(iRow, 1).value=Document.GetElementsByName("fname")(0).Value
.Cells(iRow, 2).value=Document.GetElementsByName("lname")(0).Value
.Cells(iRow, 3).value=Document.GetElementsByName("Add1")(0).Value
.Cells(iRow, 4).value=Document.GetElementsByName("Add2")(0).Value
MsgBox "Data Added Sucessfully",vbinformation
Document.GetElementsByName("fname")(0).Value=""
Document.GetElementsByName("lname")(0).Value=""
Document.GetElementsByName("Add1")(0).Value=""
Document.GetElementsByName("Add2")(0).Value=""
End With
objWorkbook.save
objWorkbook.close
Set objWorkbook = Nothing
Set objExcel = Nothing
End Sub
</script>
<style type="text/css">
fieldset {
border: #00cc00 2px solid;
padding: 10px;
color:green;
</style>
<body
<form>
<fieldset>
<legend>Csharpcorner</legend>
<center>
<img src="C:\Users\Karthikeyan.K\Desktop\Add-Male-User.png" alt="Mountain View"><br>
First name:<br> 
<input type="text" name="fname" Value=""><br>
Last name:<br>
<input type="text" name="lname" Value=""><br>
Address1:<br>
<input type="text" name="Add1" Value=""><br>
Address2 :<br>
<input type="text" name="Add2" Value=""><br>
<br>
<input type="button" onclick="Sample()" value="Submit" /><br>
</center>
</fieldset>
<form>
</body>
</html>