Generate a Word document (docx) using data from an XML file / Convert XML to a Word document based on a template

后端 未结 3 1096
生来不讨喜
生来不讨喜 2021-01-31 22:57

I have an XML file with the data that I need to be populated on a Word document.

I need to find a way, to define a template which can be used as a base line to populate

3条回答
  •  不思量自难忘°
    2021-01-31 23:55

    Ok, found a detailed guide on using XSLT as a template to generate the Word document here: Using XSLT and Open XML to Create a Word 2007 Document.

    Looks like even though this article is for Word 2007, it works perfectly in Word 2016.

    Only issue with this method is if changes are needed to the template later on, it takes a lot of effort to update the xslt file and it's not user friendly to do so since it cannot be updated in Word itself and the actual XML of the document needs to be manipulated.

    On the plus side, document generation is VERY flexible with all the power available through XSL (foreach, variables, if conditions etc.)

提交回复
热议问题