none
Basic Questions RRS feed

  • Question

  • I'm building a web application in .NET 4. For this project, I need to be able to include some Word automation. The basic goal is:

    1. Create a Word template with various fields to be populated and store the template on the server

    2. A user clicks a button and the application

        a. confirms the user has Word installed on the client machine

        b. grabs the user's personal info from the database

        c. launches Word on the client machine

        d. populates all the fields

        e. Word remains open so the user can make edits and save the file locally

     

    Questions:

    1. Is there an API or tutorial site with basic instructions on how to accomplish all this

    2. Does the server need Word installed? If not, does it need a separate license? Or will the user's client license apply?

    3. If I reference the .NET Word library for Office 2010 and the user has an earlier client version, are there potential compatibility issues?

     

    Thanks very much.

    Tuesday, April 12, 2011 11:20 PM

Answers

  • Hi MCM

    You might need to ask on a site that supports ASP.NET for Q1, as there's plenty of documentation around for local automation. But automation via an asp.net page may require special steps (Steps 2a, b, c)

    For instructions on accomplishing Step 1 it would depend very much on what kind of content the template should have and what kind of content needs to be written to the document when the user clicks that button. However...

    For your scenario, it would probably be best to create the document as far as possible in the Word UI. Set it up so that it can be "filled in" using Office OpenXML (see OpenXMLDeveloper.org and the Open XML SDK forum) - we can discuss this in a bit more detail if you provide information on what kinds of things need to be filled in with what sort of information.

    Once your application has generated this file, server-side, using the standard Packaging and XML namespaces (Word need not be installed on the server in this scenario) you can "stream" the prepared document to a file which can be opened in Word in the user's working environment.

    In this scenario, the answer to Q2 is that only the user's copy of Word needs a license. Using the open XML file format does not require any license.

    Also, in this scenario you require no reference to any Office library (Q3).

    You can generate the document using the Word 2003 XML file format (which is not standardized and will not support any technology introduced in Word 2007 or 2010), in the Word 2007 docx file format, or the Word 2010 docx file format. If it's not clear which version of Word the user will have, I recommend the Word 2007 file format. A compatibility pack was released for this version that is installed if AutoUpdate is active on the machine and can also be installed via download. This enables Word versions back to Word 2000 to work with the 2007 docx file format (must be installed via d/l for Word 2000).

    If you were to choose "interop" then the answer to 2 would be yes, you'd need a license on the server if you were to generate the file in Word server-side and the answer to 3 would be, yes, you'd run into problems. In that case, better to work in VS 2010 and use the option to embed the parts of the PIA your project uses into the project, making it PIA independent.

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by MCM14 Friday, July 22, 2011 3:40 PM
    Wednesday, April 13, 2011 6:28 AM
    Moderator

All replies

  • Hi MCM

    You might need to ask on a site that supports ASP.NET for Q1, as there's plenty of documentation around for local automation. But automation via an asp.net page may require special steps (Steps 2a, b, c)

    For instructions on accomplishing Step 1 it would depend very much on what kind of content the template should have and what kind of content needs to be written to the document when the user clicks that button. However...

    For your scenario, it would probably be best to create the document as far as possible in the Word UI. Set it up so that it can be "filled in" using Office OpenXML (see OpenXMLDeveloper.org and the Open XML SDK forum) - we can discuss this in a bit more detail if you provide information on what kinds of things need to be filled in with what sort of information.

    Once your application has generated this file, server-side, using the standard Packaging and XML namespaces (Word need not be installed on the server in this scenario) you can "stream" the prepared document to a file which can be opened in Word in the user's working environment.

    In this scenario, the answer to Q2 is that only the user's copy of Word needs a license. Using the open XML file format does not require any license.

    Also, in this scenario you require no reference to any Office library (Q3).

    You can generate the document using the Word 2003 XML file format (which is not standardized and will not support any technology introduced in Word 2007 or 2010), in the Word 2007 docx file format, or the Word 2010 docx file format. If it's not clear which version of Word the user will have, I recommend the Word 2007 file format. A compatibility pack was released for this version that is installed if AutoUpdate is active on the machine and can also be installed via download. This enables Word versions back to Word 2000 to work with the 2007 docx file format (must be installed via d/l for Word 2000).

    If you were to choose "interop" then the answer to 2 would be yes, you'd need a license on the server if you were to generate the file in Word server-side and the answer to 3 would be, yes, you'd run into problems. In that case, better to work in VS 2010 and use the option to embed the parts of the PIA your project uses into the project, making it PIA independent.

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by MCM14 Friday, July 22, 2011 3:40 PM
    Wednesday, April 13, 2011 6:28 AM
    Moderator
  • I'm not familiar with OpenXML, but I will take a look.

    Regarding the type of content...

    I would create the document 99% of the way with some images, a bunch of text, and some formatting. Then I would somehow need to designate placeholders withing the document and insert text into these placeholders from the database.

    If I'm understanding you correctly, I think what you are suggesting is:

    1. I create the document in Word.

    2. I convert the Word doc to OpenXML format. (How do I do this? And how do I create placeholders for text from the database?)

    3. I stream the completed XML document to the client machine as a .docx file.

    Do I have that right?

    Wednesday, April 13, 2011 7:21 PM
  • Hi MCM

    1. Yes. You can use bookmarks as the "data target" or content controls, depending on the version(s) of Word you're targeting. If you can tell us that, we can get into more detail...

    2. Basically, you use File/Save As in the UI...

    3. Correct :-)


    Cindy Meister, VSTO/Word MVP
    Thursday, April 14, 2011 1:43 PM
    Moderator
  • Thanks again for the help.

    1. I'm checking on what version of Word the users have installed. I'll follow up with as soon as I find out so you can explain bookmarks vs. content controls.

    2. Would the file type be .odt?

     

    Thursday, April 14, 2011 5:13 PM
  • Hi MCM

    For Word 2007 / 2010 XML file format the file type is docx or docm (with macros). That's the default document file format in those two versions.


    Cindy Meister, VSTO/Word MVP
    Friday, April 15, 2011 6:35 AM
    Moderator
  • Oh, I didn't realize docx is OpenXML.
    Friday, April 15, 2011 2:21 PM