检查VB.NET中是否存在Excel对象的好方法是什么?
我知道在VBA中我可以写一些类似的东西:
Sub TestifTableExists(name) as boolean
dim exists as range
On Error Resume Next
Set exists = ActiveSheet.listobject(name).range
On Error Goto 0
if exists is nothing
TestifTableExists= false
else
TestifTableExists= true
end if
end sub
但现在我正在转向VB.NET,并认为在VB.NET中可能有更好的方法。
答案 0 :(得分:0)
Microsoft.Office.Interop.Excel.Worksheet中有一个ListObjects函数
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim xl As New Microsoft.Office.Interop.Excel.Application
wb = xl.Workbooks.Open(FileNameWithPath)
ws = wb.ActiveSheet
ws.ListObjects(Index As Object)