What is best practice for generating Word docx's from a database? RRS feed

All replies

  • Hi Jakob,
    You've identified the sample code on how to do them. So the coding is not an issue to you. I've seen all the ways being used by the customers. I would think that the template document format might have a say on making the decision. Afterall, table will look different than content controls. Also the formatting and the types of the content will have some impact as well -- in a table cell, you could insert any type of content. For content control, there will be some limitations.

    Are you building a solution for a customer or for your own app?

    Let me know what is your concern in inserting the content.

    MS Open XML SDK Team Member

    Tuesday, July 7, 2009 10:25 AM
  • Hi Lanqing,

    So it sounds as if it might be the best way to go with the table solution:

    I would think that the custom markup solution would be better: or I.e. if it could be used to insert ooxml markup; can this be done?

    I am building a webapp for a customer. The webapp is to generate word documents based on different templates, that the customer can choose from, with content filled in from a database depending on the customer's choices. Thus it would be more flexible with the custom markup solution.

    Furhermore; it would be nice to have a way to programatically convert a docx file to a pdf file in C# with the SDK. Any suggestions on how to do the conversion programatically?

    Thursday, July 9, 2009 7:14 AM
  • Hi Jakob,
    So far as I know, there're two ways for you to complete the format conversion:
    1. 3rd party libraries;
    2. O14 Word Service.

    btw, why do you need to convert docx to pdf? what're the contents in the documents? thanks!

    Thursday, July 16, 2009 4:16 AM
  • Hi Shuanshuang,

    I found a way to create pdfs from docxs with Microsoft Word 12 Object Library.

    I need to convert to pdf to make the documents portable outside Office 2007.

    My solution is server-side enabling clients to dynamically create documents in docx and pdf from templates with content placeholders (using custom markup) populated from a database according to the relevant client.

    Monday, July 20, 2009 3:43 PM
  • We should note that automating Word on the server is not supported. Check out the following article:

    Things should be better with the next version of Office.
    Zeyad Rajabi (MS)
    Thursday, July 23, 2009 4:40 AM
  • You could use FlexDoc ( for template-based document generation (docx) and use a convertor to convert it to your desired format, like PDF/a. FlexDoc requires the data to be merged into the template to be in XML-format. When you are using MS SQL Server, you can have SQL Server return the query-output as XML and pass this to FlexDoc.
    AltChunks is a bad practice, since only Word itself currently supports it. (commercial) file converter tools do not, making it impossible to convert the files later on to a different format.

    Tuesday, August 4, 2009 11:53 AM