• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • Last Modified:

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


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?

Regards,

Y
0
yogithite
Asked:
yogithite
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
 
yogithiteAuthor Commented:
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?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
How do you open the database?
(Are you using a class such as CDatabase for example)
0
 
BitsqueezerCommented:
Hi,

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

Cheers,

Christian
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now