We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Data object contains HTML code - how to render with merge

I am doing a simple merge using data objects. The data contains HTML tags and instead of rendering the HTML in the Word doc, it is displaying the html code.

Here is a code sample:

// create placeholders
string[] myPlaceHolders = CreatePlaceholders(NumberOfRecords);

// create answers
object[] myAnswers = CreateAnswersList(RFPDataList, NumberOfRecords);

// create the Aspose document and perform the merge
Aspose.Words.Document doc = new Aspose.Words.Document(templateMemoryStream);

doc.MailMerge.Execute(myPlaceHolders, myAnswers);

// for looking at results on local workstation
doc.Save(@"c:\test\out.doc");

MemoryStream docStream = new MemoryStream();

doc.Save(docStream, SaveFormat.Docx);

I've been trying to search the forms but for the last few days keep getting errors.

Any pointers?

While searching Google I found the solution.

<A href="https://forum.aspose.com/t/56089</A></P>

Hi James,


It’s great you were able to find what you were looking for. Please let us know any time you have any further queries. We are always glad to help you.

Best regards,

After implementing the found solution another issue has appeared.

The place holders I inserted into the Word document now loose their formating/placement.

Before, when the html strings were not being converted, the data was positioned correctly inside the merged document.

Now that the html strings are being rendered the data acts like it's ignoring the placement and starts at the very far left.

Any ideas?

Hi James,


Thanks for your inquiry. Please attach your 1) input documents (.doc file and Html string), 2) output document showing the undesired behaviour and 3) your piece of code here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

File attached:

  • Word template
  • Word - merged document
  • C# class file containing the code that produces the merge document

Thanks

James

Hi James,

Thanks for your inquiry. I think, you can use the following code snippet to be able to merge the formatting that is specified inside Html string with the formatting of MergeField:

Document doc = new Document(@"C:\test\in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToMergeField("mf", false, false);

InsertHtmlWithBuilderFormatting(builder, " Hello word");

// Just to remove the mergefield

builder.MoveToMergeField("mf");

doc.Save(@"C:\test\out.docx");


Please find attached the InsertHtmlWithBuilderFormatting routine with this post.

I hope, this helps.

Best regards,