I want to get the document text after Mail Merge is executed. I use the following code:
- Code: Select all
using (var document = new Spire.Doc.Document())
{
document.LoadFromFile(template);
document.MailMerge.ClearFields = true;
var updateFieldsAfterMerge = needToUpdate();
foreach (var dr in dataSource)
{
var d = document.Clone();
d.MailMerge.Execute(dr);
d.IsUpdateFields = updateFieldsAfterMerge;
plainText = d.GetText(); // expect to return the merged document content
d.ViewSetup.DocumentViewType = DocumentViewType.PrintLayout;
d.SaveToFile(resultFile);
//d.LoadText(resultFile);
//plainText = d.GetText();
}
}
d.GetText() doesn't return the text with the merged values. They are blank. The merged content is returned by d.GetText() only if I save the document and then load the text (the last two commented lines of code).
Is there I way to get the merged content without save and load? I want to skip save/load operations for performance reasons.
Regards,
Velislav