none
Automatically Generate Word 2007 Documents using xml c#

    Question

  • Hay,

    I want to create a word document which is in word2010 format .docx driven from a base template or document having a number of content controls on it the job is to fill those fields of content controls by the xml document or sql Dataset.

    I am not getting a way for doing that so please help me out friends.Please tell me in a step by step approach as i am a new in word automation

    Thanks .....


    @nubh@v
    Tuesday, March 22, 2011 2:01 PM

All replies

  • Hi bluecomb,

    Thanks for posting in the MSDN Forum.

    Do you want to fill document content via a xml file? Or you want to use xml file to create a Word Document? If you want to create a document by xml please use OpenXml technic.

    This is a reference for Word document. http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.documentprotection(office.14).aspx

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 24, 2011 1:43 PM
  • hay thanks Tom,

     

    But i want to create the document from the predesigned template and want to fill this template using xml or sql database in c#

     

     


    @nubh@v
    Thursday, March 24, 2011 2:32 PM
  • Hi blucomb,

    Do my want to create a Word template solution in the Visual Studio. And fill the document’s content via xml or sqlsever data in this solution?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 28, 2011 5:47 AM
  • Hay Tom,

    Thats what i am requested for, i want to generate a document(word 2010 .docx) from a template (.dotx) or any other base format( template .docx) having a number of fields of data to be filled by the sql server or the xml from the visual studio like as images(at specific location on the document), text with formating,document background watermark etc.

    And then save this as password protected document.

    Please help me Thanks ........In Advance


    @nubh@v
    Wednesday, March 30, 2011 10:58 AM
  • Hi blucomb,

    I suggest you create a word template solution the handle your issue.

    In you solution, I recommend you follow these steps:

    1.      Edit your Word template. Fill the content that will never be changed in the future.

    2.      Put content control such as text plaint, picture box, rich text plaint etc. in the place where you want to fill data.

    3.      Create a connector to you Sql Server or create an xml reader to receive data from the server or xml file in the ThisDocument_Startup method.

    4.      Fill your data in the content control in the ThisDocument_Start method.

    5.      Set the PassWord property of the document.

    Now, your document will be protected via Password. And all of data will be filled automatically.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 31, 2011 10:16 AM
  • thanks tom, but can u give a code snippet to do that?
    @nubh@v
    Thursday, March 31, 2011 10:48 AM
  • Hi bluecomb,

    Would you please tell me you develop environment? If you have no specific need on develop environment I will build a sample solution via Visual Studio 2010, Office 2010, Windows7. In this solution I will show you fill the document via xml data. I will provide it at Monday (E+8 time zone).

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 01, 2011 6:21 AM
  • Hi Tom, I am using the same Environment VisualStudio 2010,Windows 7 , and the office2010 also have openxml sdk installed.

    Thanks for your Kind Help.........


    @nubh@v
    Saturday, April 02, 2011 3:46 AM
  • Hay tom Please post the solution i am still Waitimg for it
    @nubh@v
    Monday, April 11, 2011 10:25 AM
  • Hi bluecomb,

     

    Thanks for your patient, I will update a sample solution to skydrive tomorrow.

      

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 11, 2011 11:56 AM
  • Hi bluecomb,

     

    This is the url to download the sample. http://cid-bfdf05e934413519.office.live.com/self.aspx/Sample%20Code%20for%20MSDN%20Forum/ImplementData.zip .

     

    In this sample, I create a xml file which named “sample.xml” and in the solution I use an action pane to find this file and add it to the document.

     

    I hope this sample can help you.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 12, 2011 6:55 AM
  • Sorry Tom To reply So late, I got Some Hardware Issues So it take More then Enough time... Thanks for your Effort it also helped me alot but I think may be i an unable to Clearly give a Idea about what i need to do. I just need to Create a Document with Some field Need to be filled by the Win form or Database Data like as name. Just as in case of a bill there is a preformed paper on which the name of the Customer is entered at the time of purchase. This all need to be done in Background. Please try to give a help solution for that.... Thanks in Advance... And thanks for that help file....
    @nubh@v
    Monday, April 25, 2011 6:48 PM
  • Hi bluecomb,

     

    If you want to do all of your goals in background, I would recommend you write the business in the ThisDocument_Startup method.

     

    In my sample code I create an interface for data source, you’re able to implement this interface to create a data provide to generate data and nothing will be change in the Word document.

     

    If you have any questions, please feel free to let me know.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 26, 2011 8:21 AM
  • Hay Tom,

    Thanks for your help but i am unable to Implement the Solution Please explain how to used it in Backgroud.

    your solution updates the text fields in the Document but i need to update the Image field also when i use the same logic to upadte image control i do nothing..

    Please Help..

    Thanks and Sorry to Reply Late...


    @nubh@v
    Monday, June 20, 2011 4:01 PM
  • Hi bluecomb,

     

    I think you can get HtmlBody from the item and modify tag as a string. The work round which I provided will work.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 23, 2011 8:19 AM
  • Tom Sorry about the first post, hit the wrong key.

     

    I have a customer that is looking to populate a WORD document/template using XML from our application. Similar to what Bluecomb is requesting. We are not capable of doing this. I saw this post and wanted to find out if you could recommend any developers I can contact. Any help or guidance would be appreciated.

    Vardog45

    Thursday, December 01, 2011 9:39 PM