JS List
asked on
Import Excel Data Using Generic Sheet Name
Hello,
I'm importing data from an excel spreadsheet into an ASP.NET web page. The problem is the sheet name keeps changing. It's always the first sheet in the excel book - but the users change the name.
Is there a generic name for the first sheet in Excel. So if the user names the sheet to "employees" - when I make a connection can I use something like [Sheet(0)]?
Using ASP.NET 4.0 and xlsx file.
Here's my typical connection: (Source name not complete path here.)
In Web.config
<add name="csXLMembers" connectionString="Provider =Microsoft .ACE.OLEDB .12.0;Data Source=...\Members.xlsx;Ex tended Properties=Excel 12.0"/>
Code Behind aspx Page
Dim conString As String = ConfigurationManager.Conne ctionStrin gs("csXLMe mbers").Co nnectionSt ring
**** The following line is where I want to use a generic name instead of Sheet1$
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", con)
JS
I'm importing data from an excel spreadsheet into an ASP.NET web page. The problem is the sheet name keeps changing. It's always the first sheet in the excel book - but the users change the name.
Is there a generic name for the first sheet in Excel. So if the user names the sheet to "employees" - when I make a connection can I use something like [Sheet(0)]?
Using ASP.NET 4.0 and xlsx file.
Here's my typical connection: (Source name not complete path here.)
In Web.config
<add name="csXLMembers" connectionString="Provider
Code Behind aspx Page
Dim conString As String = ConfigurationManager.Conne
**** The following line is where I want to use a generic name instead of Sheet1$
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", con)
JS
ASKER
This didn't work. I see many references on the web to do it this way. But I couldn't get it to work.
what do you mean by "didnt work"? any errors? results weren't what you expected?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The responses didn't work.
string sheetName = dtExcelSchema.Rows[0]["TAB
source: http://aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-using-ADO.Net-and-C.aspx