none
Automating Word Documents RRS feed

  • Question

  •  I would like to do the following can you point me in a good direction:

    1. Build a template form (Test Document)

    2. Add custom XML tags to key portions in the document (Values etc) in tables

    3. Save the document as XML (stored on a database)

    4. Embed some custom C# in the document to do some automation (Button)

    5. Convert "Document" to HTML to be run by technician (looks the same as Original test document) where he/she inputs the values requested and runs some of the automation.

    6. save results from step 6 in database with as XML or database format.

    We currently have Office 2010 and have downloaded VS 2010 (trial). I would like to build a simple demo to convince my boss.

    Thank you for your time

    • Moved by CoolDadTx Tuesday, July 9, 2013 7:09 PM Office related
    Tuesday, July 9, 2013 3:22 PM

Answers

All replies

  • When it comes to "accessing [part of Office] Documents" you have to be very certain to understand the major differences between pre-2010 and 2010 Formats for office.

    .doc, .xls and the like are Propeitary Formats. The only thing that can read and write them reliably is the Office.Interop wich means Office has to be isntalled on the system that runs the code.
    There might be third party libraries, but as .NET could just use Office Interop there was never any real impulse to create something and give it full coverage.

    .docx, .xlsx and the like are called colelctivex Open XML Formats. They are just a bunch of XML Files in a renamed .zip container. The specificatiosn are public and there is the OpenXML SDK (wich can be redistributed) to edit and create them.
    They can also be read usng OfficeInterop, but if you have openXML Formats you should not use it anymore.

    And then there is stuff like the OpenDocument Formats, wich are a totalyl different beast altogether:

    http://en.wikipedia.org/wiki/Open_Document_Format#Application_support


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Tuesday, July 9, 2013 5:33 PM
  • Please explain in non-programming terms what your proposed project should accomplish. From what I can tell (conversion between Word document, XML and HTML) I'm not convinced a Word document is the appropriate "container" for what you want to do...

    Which version of Word are you targeting and which file format (*.doc or *.docx)?

    What do you mean by "XML tags"?

    Note that it is NOT possible to embed C# in a Word document. The only code that can be stored in a Word document is VBA. It is possible to attach a VSTO solution to a Word document and the VSTO solution can be written in C#.

    Once a Word document is converted to HTML it cannot contain code or be attached to code.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, July 10, 2013 10:46 AM
    Moderator
  • To clarify, I am using Word 2010 and outputting the file in .docx format. I then used the following link to "Cookbook" a way of storing and then translating the xml from the generated docx to back again to docx.... This is all just "try to figure it out stuff"...

    msdn.Microsoft.com/en-us/library/office/ee872374(v=office.12).aspx

    (sorry wont let me send link too new to forum)

    Again thanks for the response...

    Wednesday, July 10, 2013 1:17 PM
  • Cindy,

    I want to author a template / form once and in that form I would like to include xml tags such as (link)

    (sorry have to break up as not full member yet)

    http://

    xmlmapping.codeplex.com

    Then save the document as a docx document. Build a style sheet (unfortunately by hand unless you know a way) then use this form run by an ASP.net program to display the same word form for a web page - looks like the word document.

    When the user of the webpage inputs the data the tags associated with the form are defined now as they input the values they are saved with this special tag. They wont see the hash tags but that form has them associated with them. Because it is really run on the server and the word document is really just the template im not really "running" it from word. Its just my editor.

    Thank you for your time

     

    Wednesday, July 10, 2013 1:51 PM
  • The approach you propose based on the information in the link is discontinued, due to a court decision in 2009. See
    http://blogs.technet.com/b/gray_knowlton/archive/2009/12/23/what-is-custom-xml-and-the-impact-of-the-i4i-judgment-on-word.aspx?PageIndex=3

    The suggested approach is to use content controls, linked to a custom xml part, to give you "nodes" with data, linked to text in the document. See

    http://blogs.technet.com/b/gray_knowlton/archive/2010/01/04/using-content-controls-vs-custom-xml-elements.aspx
    http://blogs.technet.com/b/gray_knowlton/archive/2010/01/15/associating-data-with-content-controls.aspx

    In this scenario, no schema would be necessary on the Word side.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, July 10, 2013 2:11 PM
    Moderator
  • Cindy,

    Thank you!! I've been searching (I knew what I wanted just couldn't describe it well).

    Wednesday, July 10, 2013 2:19 PM