Imports Microsoft.VisualBasic
Public Class Class1
Public Shared Function GetAllSheetName(ByVal strFilePath As String) As String()
Dim strConn As String = String.Empty
If strFilePath.EndsWith("xls") Then
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " + _
"Data Source=" + strFilePath + "; " + _
"Extended Properties='Excel 8.0;IMEX=1'"
ElseIf strFilePath.EndsWith("xlsx") Then
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + _
"Data Source=" + strFilePath + ";" + _
"Extended Properties='Excel 12.0;HDR=YES'"
End If
Dim conn As OleDbConnection = New OleDbConnection(strConn)
conn.Open()
Dim sheetNames(conn.GetSchema("Tables").Rows.Count - 1) As String For i As Integer = 0 To conn.GetSchema("Tables").Rows.Count - 1 sheetNames(i) = conn.GetSchema("Tables").Rows(i)("TABLE_NAME").ToString Next conn.Close() Return sheetNames End Function End Class
原文链接:https://www.f2er.com/vb/259819.html