Microsoft Word API

This is a discussion on Microsoft Word API within the C++ Programming forums, part of the General Programming Boards category; Hi Does anyone here know of a Microsoft Word document API or object that I can use within my program ...

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Microsoft Word API

    Hi Does anyone here know of a Microsoft Word document API or object that I can use within my program to create a word document when the program is run, rather than having a document created and copying from a folder, I know this is possible in Visual Basic so I can't believe that it isn't possible using Visual C++.

    Cheers.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    You need COM...

    If you have VC++ and dont mind using MFC, then you can use class wizard to load the typelib of your version of word and create wrapper classes for it

    Loads of examples @ codeguru, codeproject and other sites you can find on the web

    As for the object model.....open up your version of word...press F11 for the VBA editor and browse the help files....all the info is there

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Hi, thanks for your reply Fordy, nice to know it is possible, I am using MFC which is good, but I am sorry I don't know what you mean about the typelib, and by a wrapper class do you mean write a class that operates from that typelib?

    Cheers.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    A typelib is a file produced with many automation objects that defines different objects, their methods and properties. Ever wondered how when sometimes you install a new office product and Visual Basic object browser can now see the classes etc.... - this is due to the typelibs for those apps. Sometimes they have a .tlb extension, sometimes they are embedded inside a dll or the exe....open classwizard in VC++ and there should be an automation tab (if memory serves me)...there you should find what you need to load the typelib. If you load it correctly you should be prosented with a list of objects to have classes created for (Word.Application, Word.Document etc)....whatever you choose will have classes created for you by VC++, they appear in the class view like other classes.

    You can also bypass MFC by using the "import" directive - more on this at the sites I mentioned earlier

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Thanks mate I will give that a go now, sometimes its not easy to fiind these things unless you know exactly what you are looking for, thanks again.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    This kinda works, although Word thinks it's a text file when you save it.
    Code:
    #include <process.h>
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
        ofstream out("new.doc");
        if (!out)
        {
            cerr << "failed to create new.doc" << endl;
            return 1;
        }
        out.close();
    
        system("new.doc");
    
        return 0;
    }//main
    gg

  7. #7
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Cheers for that code plug, but that just looks like it is creating a text fiule with a .doc extension, I need all the functionality of a word document for mail merging and stuff, but cheers for the help.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Microsoft Word documents
    By Mavix in forum C# Programming
    Replies: 8
    Last Post: 08-04-2007, 07:39 AM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. Word Count
    By simple in forum C Programming
    Replies: 12
    Last Post: 10-04-2002, 10:47 PM
  4. Retaliation towards witch king\microsoft
    By Koshare in forum Linux Programming
    Replies: 7
    Last Post: 10-19-2001, 04:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21