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 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|