我目前正在创建一个工具,它将自动将数据提交到Excel。我的问题是,我想向Excel提交多个数据。
例如:
我有两个文本框(项目1和项目2),一旦我点击提交按钮。应将数据保存在Excel表格(A1、A2)等A3中…如果用户继续提交数据。
下面是我的代码,它不断地将数据存储到A1和B1。
<html>
<head><title>XLS Data</title>
<HTA:APPLICATION
APPLICATIONNAME="XLS Data"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script type="text/vbscript">
Sub WriteXL()
strFileName = "C:\Users\ChrisLacs\Desktop\Book1.xlsx"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(strFileName)
Set objWorksheet = objWorkbook.Worksheets(1)
Const xlCellTypeLastCell = 11
objWorksheet.UsedRange.SpecialCells(xlCellTypeLastCell).Activate
iLast = objExcel.ActiveCell.Row + 1
objExcel.Cells(iLast, 1).Value = document.getElementById("item1").value
objExcel.Cells(iLast, 2).Value = document.getElementById("item2").value
objExcel.Cells.EntireColumn.AutoFit
objWorkbook.Save
objExcel.Quit
End Sub
</script>
<body>
<form>
<p>Item 1: <input type="text" id="item1" max="20" /></p>
</p>
<p>Item 2: <input type="text" id="item2" max="50" /></p>
<p><button onclick="WriteXL">SubmitL</button></p>
</form>
</body>
</html>发布于 2021-04-05 02:02:43
在Excel中,“单元”使用行,然后使用列(单元(Row_num,Col_num))。
试一试
objExcel.Cells(1, iLast).Value = document.getElementById("item1").value
objExcel.Cells(2, iLast).Value = document.getElementById("item2").valuehttps://stackoverflow.com/questions/66882754
复制相似问题