01.
Private
Function
GetExcelSheetNames()
As
List(Of
String
)
02.
Dim
dt
As
DataTable =
Nothing
03.
04.
Try
05.
If
conn.State = ConnectionState.Open
Then
06.
conn.Close()
07.
End
If
08.
conn.Open()
09.
10.
11.
dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
Nothing
)
12.
13.
If
dt
Is
Nothing
Then
14.
Return
Nothing
15.
End
If
16.
17.
Dim
excelSheets
As
New
List(Of
String
)(dt.Rows.Count)
18.
Dim
i
As
Integer
= 0
19.
20.
For
Each
row
As
DataRow
In
dt.Rows
21.
If
row(
"TABLE_NAME"
).ToString().Contains(
"$"
)
Then
22.
23.
If
row(
"TABLE_NAME"
) IsNot
Nothing
Then
24.
excelSheets.Add(GetSheetName(row(
"TABLE_NAME"
).ToString()))
25.
End
If
26.
End
If
27.
i += 1
28.
Next
29.
30.
excelSheets = excelSheets.Distinct().ToList()
31.
32.
Return
excelSheets
33.
Catch
ex
As
Exception
34.
Return
Nothing
35.
End
Try
36.
End
Function
37.
Private
Function
GetSheetName(str
As
String
)
As
String
38.
Dim
use
As
Integer
= 0
39.
Dim
len
As
Integer
= str.Length
40.
41.
42.
For
i
As
Integer
= 0
To
len - 1
43.
If
str.Substring(i, 1) =
"$"
Then
44.
use = i
45.
End
If
46.
Next
47.
48.
Dim
tmp
As
String
49.
If
use = 0
Then
50.
tmp = str
51.
Else
52.
tmp = str.Substring(0, use + 1)
53.
End
If
54.
Return
tmp
55.
End
Function