Getting excel sheet names

  • Thread starter Thread starter Gomathi
  • Start date Start date
G

Gomathi

hi all,

I'm using oledb provider to open an excel file. And i want to get all the
sheet names of that file.
Is anybody know how to do that?
Expecting ur reply,

Thanks in advance.

Gomathi
 
Gomathi:

The following code sample shows one approach to obtaining the sheet names of
an Excel workbook. You will need a reference to the Excel Object Library,
of course.

Excel.Application xl = new Excel.Application();

Excel.Workbook wkb = xl.Workbooks.Open(@"H:\testbase.xls",Type.Missing
,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);


foreach(Excel.Worksheet wks in wkb.Sheets)

{

txtSheetNames.Text += wks.Name + ";";

}

wkb.Close(Type.Missing,Type.Missing,Type.Missing);

xl.Quit();

There is a another method for access sheet information, however, it includes
named ranges in addition to the sheet names. Please see the following KB
article for more information.

http://support.microsoft.com/default.aspx?scid=kb;en-us;318452

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


hi all,

I'm using oledb provider to open an excel file. And i want to get all the
sheet names of that file.
Is anybody know how to do that?
Expecting ur reply,

Thanks in advance.

Gomathi
 
Back
Top