对于脚本编写,我仍然是一个新手,所以如果这是一个简单的错误,请原谅我。
我试图使用我用CMD创建和执行的VBS脚本在一个不断更新的CSV文件中显示最后一行。我一直在拉和修补来自多个来源的代码。
到目前为止,我只能让它拉上一行,而不知道如何将它切换到底部。我的代码有点粗糙。任何帮助都将不胜感激。
到目前为止,这是我的代码:
Option Explicit
Dim objExcel
Dim excelPath
Dim workSheetCount
Dim counter
Dim currentWorkSheet
Dim usedRowsCount
Dim row
Dim top
Dim Cells
Dim curRow
Dim word
excelPath = "c:\Test\test.csv"
WScript.Echo "Reading Data from " & excelPath
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = 0
objExcel.Workbooks.open excelPath, false, true
workSheetCount = objExcel.Worksheets.Count
WScript.Echo "We have " & workSheetCount & " worksheets"
For counter = 1 to workSheetCount
WScript.Echo "-----------------------------------------------"
WScript.Echo "Reading data from worksheet " & counter & vbCRLF
Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
usedRowsCount = currentWorkSheet.UsedRange.Rows.Count
top = currentWorksheet.UsedRange.Row
Set Cells = currentWorksheet.Cells
For row = 0 to (usedRowsCount-1)
curRow = row+top
word = Cells(curRow).Value
WScript.Echo (word)
Next
Next
Set currentWorkSheet = Nothing
objExcel.Workbooks(1).Close
objExcel.Quit
Set currentWorkSheet = Nothing
Set objExcel = Nothing发布于 2018-05-17 19:16:27
嗯..。
filename = "C:\Test\test.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do Until f.AtEndOfStream
line = f.ReadLine
Loop
f.Close
WScript.Echo lineCSV是一种文本格式,因此您可以轻松地使用FileSystemObject方法处理它,而无需使用Excel。
https://stackoverflow.com/questions/50398565
复制相似问题