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: .

Imports Data from XLS file to DataGridView VB 2005 Read Text file, CSV file to DataGridView

Gửi phản hồi

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

Tháng Chín 2008
T2 T3 T4 T5 T6 T7 CN
« Tháng 8   Tháng 10 »
1234567
891011121314
15161718192021
22232425262728
2930  

Follow

Get every new post delivered to your Inbox.