Get XLS Sheet Name (VB2005)
Tháng Chín 12, 2008 at 1:01 sáng Để lại phản hồi
Public Sub GetSheetNames(ByVal path As String, ByRef str() As String)
If IO.File.Exists(path) AndAlso IO.Path.GetExtension(path) = “.xls” Then
Dim app As New Excel.Application
Dim i As Integer = 0
Dim WB As Excel.Workbook
Try
WB = app.Workbooks.Open(Filename:=path)
If WB IsNot Nothing Then
For Each ws As Excel.Worksheet In WB.Sheets
str(i) = ws.Name
i = i + 1
Next
WB.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(WB)
WB = Nothing
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
app = Nothing
End Try
End If
End Sub
Entry filed under: VB.NET. Tags: .
Trackback this post | Subscribe to the comments via RSS Feed