'Declare the object of Excel
Dim exlBook As Excel.Workbook
Dim exlSheet As Excel.Worksheet
Dim exlApp As Excel.Application = New Excel.Application()
Dim exlSheet As Excel.Worksheet
Dim exlApp As Excel.Application = New Excel.Application()
'Open the object of the excel file
exlBook = exlApp.Workbooks.Open(filepath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
exlSheet = DirectCast(exlBook.Worksheets(1), Excel.Worksheet)
exlSheet = DirectCast(exlBook.Worksheets(1), Excel.Worksheet)
'get the count of excel file usedRange rows
RecordCount = exlSheet.UsedRange.Rows.Count
'get the value of the current cell
Dim _strVendCode As String = exlSheet.UsedRange.Range("H" + row.ToString()).Value.ToString().Trim()
'Finally
If Not exlBook Is Nothing Then
exlBook.Close()
ReleaseComObject(exlBook)
End If
exlBook.Close()
ReleaseComObject(exlBook)
End If
exlApp.Quit()
exlApp.Workbooks.Close()
exlApp.Workbooks.Close()
'释放对象资源
ReleaseComObject(exlSheet)
ReleaseComObject(exlApp)
exlSheet = Nothing
exlBook = Nothing
exlApp = Nothing
'强制回收内存
GC.Collect()
''' <summary>
''' release the object of the excel intantiate
''' </summary>
''' <param name="obj"></param>
''' <remarks></remarks>
Protected Friend Sub ReleaseComObject(ByVal obj As Object)
If Not obj Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
End If
End Sub
''' release the object of the excel intantiate
''' </summary>
''' <param name="obj"></param>
''' <remarks></remarks>
Protected Friend Sub ReleaseComObject(ByVal obj As Object)
If Not obj Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
End If
End Sub