CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Automate Excel 2010 from c++

    I need to bring someone up to speed very quickly (like now - don't ask!) on being able to automate Excel 2010 from Visual Studio c++ (not using MFC). The person is fairly knowledgeable with c++ but knows nothing of OLE, ODBC, ATL, COM etc . The required tasks involve producing formatted Excel charts from csv data files and then saving these charts as pdf files.

    Can any guru recommend a book specially teaching and demonstrating how to automate office (and Excel in particular) using c++ - something along the lines of 'An idiots guide to automating Excel using c++' or 'Teach yourself Excel automation using c++ in 24 hours'?

    Thanks.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Automate Excel 2010 from c++

    C++, "very quickly" and "knows nothing about OLE, ODBC, ATL, COM" hardly come along, IMHO. C++ is not the best choice for office automation. VB or C# look much more friendly in this aspect.

    And no, never heard of a book of this kind.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Automate Excel 2010 from c++

    COM in C++ is going to be "weird" nomatter how you approach it.
    MFC and ATL (and some other libs) allow you to create C++ wrappers around the COM objects that will make them easier to use. But you're still going to have to know a decent base about COM in general.

    And then you'll need to get up to speed on the specific excell COM objects and an overall grasp of microsoft's DOM in this regard.

    The question really I guess is...
    do you want someone that'll just "mess around" with some samples without really understanding how/what they're doing but with some experimentation and googling manages to "make it appear it works how you want to".
    or
    do you want someone that knows what they're doing.


    There's a few samples out there for Excel from C++ (raw, unwrapped COM interface) that could be used for the first.
    the second is going to take several days to learn how to work with COM in general (how/what are variants, and how/what are BSTR's and how do you convert from C++ types to COM types). Learn about IUnknown, IDispatch, and how to 'convert' from one interface to another.
    Learn to work with one of the wrapper libs (MFC, ATL, cxCOM, ... or create your own).
    Learn the Excel DOM, and then program with the Excel COM objects.
    Depending on needs, this could also need extra work if you want to embed excel 'controls' on your views/dialogs. or if you want to programmatically work with the DOM.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Automate Excel 2010 from c++

    COM in C++ is going to be "weird" no matter how you approach it.
    I know! I've still got the scars from when I first got involved with this quagmire.

    do you want someone that'll just "mess around" with some samples without really understanding how/what they're doing but with some experimentation and googling manages to "make it appear it works how you want to".
    or
    do you want someone that knows what they're doing.
    Some one that knows what they they are doing - but this mess is not of my making. The person concerned was appointed against my recommendation but senior management have (as usual!) dumped the whole mess onto me. Discussions with them are still ongoing about this

    However, in view of the comment from Ignor in post #2, I've now had further discussions with the person and it transpires that he has some c# experience and so I'm pursuing using c# rather than c++ as the person concerned seems more confident doing this in c# instead of c++.

    Thank you for your useful suggestions.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Automate Excel 2010 from c++

    Well, I don't think there's anything "weird" in C++ COM.

    I started using COM with C++ more than a dozen years ago, and successfully did that in several projects, including Excel automation, though not really complex one. However it never was "very quickly", and I knew quite a lot about COM and ATL to the moment. Later I did PowerPoint automation with VB6.0, and got some experience to be able to compare approaches. Later I had a chance to implement several COM servers, and those always were in C++, designed to be used in C#, PHP and C++.

    Based on all this, I made my statement in post #2. So again, nothing weird, but it won't be quick, and will require a good deal of delving into details of COM itself in general, and ATL/MFC in particular.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured