easy 500 pts: VC++ n ODBC with MS Excel, how to get sheet name and count

Posted on 2009-12-31
Medium Priority
Last Modified: 2013-11-20

Hi Experts,

I am using MS Excel sheets with VC++ [ODBC Connection]. I am able to read and write in excel sheet. But I dont know how to read the sheet name and how many sheets are available. Can any one point me to relevant logic?


Question by:yogithite

Accepted Solution

ghoshsaikat83 earned 2000 total points
ID: 26153219
LVL 45

Expert Comment

ID: 26153376
I don't know if that is possible using an ODBC connection.

Is there any reason you do not wish to use automation  - that is how the link from the previous comment is doing things.

Author Comment

ID: 26153462
I am using MS Excel as database. I am creating tables in excel sheet. Each worksheet has one table and each worksheet is named as title of table.

Is it not possible?
LVL 45

Expert Comment

ID: 26153590
How do you open the database?
(Are you using a class such as CDatabase for example)
LVL 24

Expert Comment

ID: 26167785

the problem with the solution of the link in the first answer is that you must first open an installed Excel as application to access the file.
Opening an Excel file as ADO gives you the possibility to open it as database like the author wrote. No local Excel needed.

To answer the question: In addition to ADO you need a reference to ADOX. Here you can use the ADO connection to access further objects which contains a "tables" list which contains all the informations you need.
In VBA I do it on the attached way (sorry, I don't know the exact syntax in C++ to convert it in C but I think you will get that on your own):

Public Function fnXCLADOTables(cnXCLConnection As ADODB.Connection) As ADOX.Tables
Dim objCatalog As ADOX.Catalog
Set objCatalog = New ADOX.Catalog
objCatalog.ActiveConnection = cnXCLConnection  
Set fnXCLADOTables = objCatalog.Tables
Set objCatalog = Nothing
End Function



Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

850 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