CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 1999
    Posts
    66

    .NET (C#) and Word Application

    Hi all,

    I’m a C++ developer and a very beginner in both C# (.Net) and Word Programming. What my company wants next is something like this: from different texts to build a Word 2007 document and then open this in the real Word 2007 application to give the user the possibility to change the document as usual with all possibilities (Menüs, Panels, etc.). Well my problem is that the Word 2007 must be embedded in our C# - Application (WinForms).
    Knows somebody a solution to do this: embed the Word 2007 application in WinForms or if better maybe in WPF? For any idea thank you in advance.

    Best Regards,
    Emil

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: .NET (C#) and Word Application

    1. Right click on the project solution and click Add Reference...
    2. Window will open; There click on the COM tab.
    3. Scroll down untill you see Microsoft Word Object Library.

    Give it a try.....
    Regards,
    MMH
    Rate my post if you find it usefull.

  3. #3
    Join Date
    Sep 2004
    Posts
    1,361

    Re: .NET (C#) and Word Application

    Be aware, you end users must have Word installed to run your application. In fact, they will have to have every version of Word you specifically include. Normally you just use the latest version which has the backward compatibility. In either case, if someone does not have Word installed, then they can not use your app.

    I was using the Excel COM object to import excel spread sheets and that is when I found out everyone had to have excel installed.

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: .NET (C#) and Word Application

    If your program simply has to work with Word 2007, then you are VERY lucky. For the first time, the file format is actually officially defined, and you can manipulate it without needing any of the office components. The new .docx (and all of the office formats which are .???x are actually just zip files with most of the data stored as XML). The complete specifications are available freely from Microsoft!

    For other versions, the issues have basically been covered, you need the Office Application installed, and you use the providd object model. THe big "gotcha" for many implementations is that the License agreement for the regular copies of office, prohibit installation on a Server....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Jan 2008
    Posts
    20

    Re: .NET (C#) and Word Application

    Hey all,

    I have been doing something similar for the last few weeks (with embedded word app in my form).

    Firstly, CPUWiz, can you expand on what you mean by,
    the file format is actually officially defined, and you can manipulate it without needing any of the office compnents.
    ??

    And also, I have developed my app on XP with office03, and my client is running vista with office07. Everything works fine except that in word03 i was able to disable the toolbars i dont want, with code as below.

    Code:
    int counter = wd.ActiveWindow.Application.CommandBars.Count;
    for(int i = 1; i <= counter;i++)
    {
         try
        {
            wd.ActiveWindow.Application.CommandBars[i].Enabled = false;
            String nm=wd.ActiveWindow.Application.CommandBars[i].Name;
            if (nm.Equals("Formatting"))
                wd.ActiveWindow.Application.CommandBars[i].Enabled = true;
        }
    }
    but this doesn't disable the same command bars in word07.
    Im using the COM objects:
    * Microsoft Office 11.0 Object Library
    * Microsoft Word 11.0 Object Library

    do i need new object libaries? and where do i get these from.

    Thank you for your help
    (.NET Version 2.0.50727) VS2005

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: .NET (C#) and Word Application

    1) All versions of Word prrior to 2007, used a proprietary file format to store the documents (the .doc extension). While there were many people who (with varying degrees of success) reverse engineered the format, and were able to make modifications, the only supported way was to use the object model. Using the object model required the appropriate version of word to be installed on the system. With the release of Office 2007, a new file format (appending an x to the old extension like .docx) was developed and set as the default for new documents. This file format is well published by Microsoft, and you can now manipulate documents in this format without using the object model, and therefore in environments where the application is NOT installed, simply by opening the file.

    2) I would have to do a little research to confirm but I believe you need the Office 12 libraries for 2007...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Jan 2008
    Posts
    20

    Re: .NET (C#) and Word Application

    Yes it looks like the office 12 libraries are needed, and only availble in an office07 environment.

    o well looks like i will have to upgrade my office package then. *sigh
    at least it is fully backwards compatible

    thank you all
    (.NET Version 2.0.50727) VS2005

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