Hi,
I have the below code written to import data from one excel file to a datatable while automation script execution in Silk Test Workbench 15.5
When this code is executed in my machine, I don't see the Driver file getting opened. But, when I executed in another machine, I could the Driver file is getting opened and then getting closed. Why I am seeing the file in other machine?
Both the machines have Silk Test 15.5 installed and has VS 2010 and VS 2012 respectively.
My machine have VS2010 and excel 15.0 and the other machine has VS2012 and excel 16.0.
Imports SilkTest.Ntf.Wpf
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports Excel = Microsoft.Office.Interop.Excel
Public Module Main
Dim _desktop As Desktop = Agent.Desktop
Public dDataTables As New Dictionary(Of String, List(Of List(Of String)))
Public tDataTable As New List(Of List(Of String))
Public tHeaderRow As New List(Of String)
Public tDataRow As New List(Of String)
Public Sub Main()
Dim sBookName = "C:\Users\ADONRS\Desktop\Driver.xlsx"
Dim sTableName = "RPack"
Dim sSheetName = "RPack"
ImportSheet(sBookName, sTableName , sSheetName)
End Sub
Public Sub ImportSheet(sBookName As String, sTableName As String, sSheetName As String)
Dim objExcel As Excel._Application
Dim objBook As Excel._Workbook
Dim objSheet As Excel.Worksheet
Dim rowsList As New List(Of List(Of String))
objExcel = CreateObject("Excel.Application")
objBook = objExcel.Workbooks.Open(sBookName)
objSheet = objBook.Sheets(sSheetName)
Dim objRange As Excel.Range = objSheet.UsedRange
Dim iRowCount As Integer = objRange.Rows.Count
Dim iColCount As Integer = objRange.Columns.Count
For iRowNo = 1 To iRowCount
Dim fieldList As New List(Of String)
If objSheet.Cells(iRowNo, 1).Value & "" = "" Then Continue For
For iColNo = 1 To iColCount
fieldList.Add(objSheet.Cells(iRowNo, iColNo).Value & "")
Next
rowsList.Add(fieldList)
Next
System.Threading.Thread.Sleep(5000)
objBook.Save()
objBook.Close()
objExcel.Quit()
ReleaseObject(objSheet)
ReleaseObject(objBook)
ReleaseObject(objExcel)
If dDataTables.ContainsKey(sTableName) Then dDataTables.Remove(sTableName)
dDataTables.Add(sTableName, rowsList)
End Sub
Public Sub ReleaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
End Module