We help IT Professionals succeed at work.

Import Excel Data Using Generic Sheet Name

JS List
JS List asked
on
290 Views
Last Modified: 2014-06-25
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;Extended Properties=Excel 12.0"/>

Code Behind aspx Page
 Dim conString As String = ConfigurationManager.ConnectionStrings("csXLMembers").ConnectionString

****  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
Comment
Watch Question

Big MontyWeb Ninja at large
CERTIFIED EXPERT

Commented:
you could use the following code to obtain the sheet name:

string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"];

source: http://aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-using-ADO.Net-and-C.aspx

Author

Commented:
This didn't work.  I see many references on the web to do it this way.  But I couldn't get it to work.
Big MontyWeb Ninja at large
CERTIFIED EXPERT

Commented:
what do you mean by "didnt work"? any errors? results weren't what you expected?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
The responses didn't work.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.