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

Posted on 2009-12-31
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
    LVL 5

    Accepted Solution

    LVL 43

    Expert Comment

    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

    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 43

    Expert Comment

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

    Expert Comment


    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



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
    Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now