Dynamic word template creation from HTML to docx with Aspose Word in Dot net

Hi Team,

We need to implement a functionality that creates a dynamic word document. When I say dynamic, our idea is that we need to have a base template and that might contain some para and when we need to generate a document based on some rules that says what para should be visible and what content should be visible and then generate the final output.

We are looking to have the base template as an html and have the output as docx, we know that Aspose supports html to docx conversion but to arrive at the final version of html we need to apply many rules and remove/change some content on it. Does Aspose have same rule that apply to Docx applies for html as well and is there any POC from Aspose that explains a complex conversion of html to Docx.

Regards,
Karthikeyan

@Karthik_Test_account There two powerful ways to create dynamic documents using Aspose.Words:

  1. Classic Mail Merge
  2. And more advanced LINQ Reporting Engine

But using HTML as a template is not the best option. Please note, Aspose.Words is designed to work with MS Word documents. HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one format to another. Upon reading HTML document (or any other documents) Aspose.Words converts them to Aspose.Words Document Object Model, which perfectly fit MS Word documents, but there might be peculiarities when not native format, such as HTML, is loaded.
So I would recommend you to use DOCX documents as a template.

@alexey.noskov - Thank you for the information. I went through the Mail merge concepts I just want to see an example of how to do CURD operations (Insert, Update, delete) with these two features can you please share a sample code snippet for those?

Thanks,
Karthikeyan

@Karthik_Test_account In case of mail merge the special fields - merge fields are used as placeholders. When you execute either simple email merge or mail merge with regions, the placeholders are replaced with data from the data source. This is how a simple scenario works (insertion). If you would like to have a conditional content in the template, you can using IF field. For example:
{ IF "{ MERGEFIELD myField }" = "true" "This text will be visible if value of 'myField' is true" "This is false text." }

The same can be achieved using LINQ Reporting Engine, but in this case text placeholders with special syntax are used.

You can find code examples and sample templates on our GitHub.