微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将多个数据提交到 Excel

如何解决将多个数据提交到 Excel

我目前正在创建一个工具,可以自动将数据提交到 Excel。 我的问题是,我想向 Excel 提交多个数据。

例如:

我有 2 个文本框(第 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>

解决方法

在 Excel 中,“单元格”使用行,然后使用列 (Cells(Row_num,Col_num))。

试试

objExcel.Cells(1,iLast).Value = document.getElementById("item1").value
objExcel.Cells(2,iLast).Value = document.getElementById("item2").value

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。