Solved

ADO.Net - Excel - 1st Worksheet

Posted on 2009-06-29
3
382 Views
Last Modified: 2013-12-17
I use ADO.Net to open an Excel workbook.

If I know the name of the first worksheet, I can get the data no problem.

Is there a way to reference the first worksheet whatever its name is when creating the Command object?
0
Comment
Question by:Éric Moreau
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
ID: 24735808
C# - Retrieve Excel Workbook Sheet Names.
http://www.codeproject.com/KB/aspnet/getsheetnames.aspx
0
 
LVL 15

Assisted Solution

by:mohan_sekar
mohan_sekar earned 100 total points
ID: 24735813
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 24735913
Excellent.

The answer is: cn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)
or: cn.GetSchema("Tables")

which both return a datatable.

The only problem with this is that you have no clue which sheet is the first one (as they seem to be sorted by name).

It is not really a problem for me as the workbook contains a single worksheet (but my tests showed me multiple worksheets).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question