Is it possible to use an html file as a template for an Aspose mail merge?

Hi,

Would it be possible to create a template in HTML, insert mail merge fields some how (by using surrounding %s’ or something) and then run the Aspose mail merge function on it?

If it is, could you provide an example/show me some documentation as I have been unable to do so.

Thanks,
Adam

Hi Adam,

Thanks for your query.

In your case, I suggest you please use the Mustache Template Syntax for Mail Merge. The
MailMerge.UseNonMergeFields property, when true, specifies that in addition to MERGEFIELD fields, mail merge is performed into some other types of fields and also into “{{fieldName}}” tags.

When UseNonMergeFields is set to true, Aspose.Words will perform mail merge into the following fields:

MERGEFIELD FieldName

MACROBUTTON NOMACRO FieldName

IF 0 = 0 "{FieldName}" ""

Also, when UserNonMergeFields is set to true, Aspose.Words will perform mail merge into text tags “{{fieldName}}”. These are not fields, but just text tags.

Please check this blog post and following code example for your kind reference. I have attached the input and output documents with this post.

Document doc = new Document(MyDir + "in.htm");
String[] fieldNames = new String[] { "name", "value"};
Object[] fieldValues = new Object[] { "Chris", 10000};
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.Execute(fieldNames, fieldValues);
doc.Save(MyDir + "Out.docx");

Hi,

Thanks for the reply…

Also would regions still work the same? e.g using {{TableStart:Orders}}

And I read somewhere that there may be issues with formatting in the produced .docx files because some html features are not implemented in Microsoft Word. Just to check, could this include CSS stylings? If so, would saving to .pdf correct these problems?

Thanks,
Adam

Sorry!

I should have read that article more clearly as it answered many of my questions…

One thing i couldn’t find though… My main reason for looking into this is because Microsoft Word doesnt support a min-height type styling property.

If we were to surround an HTML table in a div and set a min-height property, would Aspose/Rendering Enginer respect that property or not?

Thanks,
Adam

Hi Adam,

Thanks for your inquiry. Please
note that Aspose.Words mimics the same behavior as MS Word do. If you load the input html in MS Word and
convert it to Doc/Docx, you
will get the same output generated via Aspose.Words.

Please set the style ‘min-height’ to Div tag and load the HTML document in MS Word and check the expected behavior.

Moreover, upon
processing HTML, some features of HTML might be lost. You can find a
list of limitations upon HTML exporting/importing here:
https://docs.aspose.com/words/net/load-in-the-html-html-xhtml-mhtml-format/
https://docs.aspose.com/words/net/save-in-html-xhtml-mhtml-formats/

Hope this answers your query. Please let us know if you have any more queries.