Click here to Skip to main content
12,558,909 members (44,820 online)
Click here to Skip to main content
Add your own
alternative version


106 bookmarked

C# - Retrieve Excel Workbook Sheet Names.

, 25 Aug 2004
Rate this:
Please Sign up or sign in to vote.
This article provides a way to retrieve the worksheet names of an Excel Workbook. This can be used to query a workbook using ADO.NET if you do not know the names of the worksheets.


There are many examples using ADO.NET to query an Excel Workbook but they all have a limitation, you must know the worksheet name. This might work if you know the name of the worksheet, but what if you don't? If your program is dynamic and your sheet names differ for each Excel workbook, you need a way to extract the names of the sheets. The code example provides you with a way to retrieve the work sheet names.

The following method returns a string array containing the names of the sheets. The method also shows how to loop through the array. The method has one input parameter excelFile which is the location of the Excel file.

Code Example

/// <span class="code-SummaryComment"><summary>



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Kenny Young
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionA Better Way??? Pin
Anonymous30-Oct-04 12:32
sussAnonymous30-Oct-04 12:32 
AnswerRe: A Better Way??? Pin
Mike Ellison30-Oct-04 13:59
memberMike Ellison30-Oct-04 13:59 
AnswerRe: A Better Way??? Pin
gg423713-Nov-09 0:44
membergg423713-Nov-09 0:44 
Good point!

However, if you need to do some other, more complicated, stuff on Excel files in C# or VB.NET you should take a look at GemBox.Spreadsheet .NET Excel component.

It supports reading and writing XLS, XLSX, CSV, ODS and HTML files in C# or VB.NET.

It has developer friendly API and is about 260 times faster than Excel Interop.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 26 Aug 2004
Article Copyright 2004 by Kenny Young
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid