Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i know the number of tables in excel file using ADO.NET ?

Status
Not open for further replies.

erxi9

Programmer
Jul 8, 2003
10
IL
How can i know the number of tables in excel file using ADO.NET ?

my program gets a excel file from the user with severals sheets in it. I want to look this file and let the user chose whitch sheet he wants.
my question is how can i using my connection get the names of the excel sheets ?
 
Hi,
Here is an example how to find out the names of the worksheets:


private Excel.Application m_Excel;
private Excel._Workbook m_WorkBook;
private Excel._Worksheet m_WorkSheet;




m_Excel = new Excel.Application();


if (m_Excel.Workbooks.Count==0)
{
m_Excel.Workbooks.Open("test.xls",,true,,,,,,,,false,,,,);
m_WorkBook=(Excel.Workbook) m_Excel.Workbooks.get_Item(1); // first workbook
for (int i=0;i<m_WorkBook.Worksheets.Count>0;i++)
{

m_WorkSheet=(Excel.Worksheet) m_WorkBook.Worksheets.get_Item(i);
MessageBox.Show(&quot;The name of the &quot; + i + &quot;sheet is : &quot; + m_WorkSheet.Name);
}
}
-obi-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top