我目前正在进行自动化测试,需要将动态值写入特定列中的现有 excel 文档,这就是我目前所拥有的。 原谅我是新手
Sub WriteTRNtoExcelDoc
Dim fileName, sheetName
fname = "<Path_To_The_File>"
sheetName = "Sheet1"
Set app = Sys.OleObject("Excel.Application")
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
' What do I do next to add a value to a specific column or cell in this
' spreadsheet?
End Sub
提前感谢!
在 VBScript 中创建一个 Excel 实例
CreateObject("Excel.Application")
可以使用已运行的 Excel 实例来抓取
GetObject(, "Excel.Application")
在工作表中,可以使用 Cells
属性访问单元格:
Set app = CreateObject("Excel.Application")
app.Visible = True
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
sheet.Cells(2,3).Value = "foo"
编辑:如果您需要在给定列中找到第一个空单元格,您可以使用以下内容:
row = 1
Do Until IsEmpty(sheets.Cells(row, 3).Value)
row = row + 1
Loop
sheet.Cells(row, 3).Value = RemPropValue