1. Get the name of the first sheet.
Public shared function getfirstsheetname (byval strfilepath as string) as string
Dim myexcel as Excel. Application = new excel. Application
Dim missing as object = system. reflection. Missing. Value
Myexcel. application. workbooks. Open (strfilepath)
Dim mybook as Excel. Workbook = myexcel. workbooks (1)
Dim sheet as Excel. worksheet = mybook. Sheets (1)
Dim strsheetname as string = sheet. Name
Mybook. Close ()
Myexcel. Quit ()
Return strsheetname
End Function
2. Get the name of all sheet.
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