Need some help in updating the word document with Aspose.Words

Hi,

We are doing a small POC using Aspose.Word.
We are creating a word document using Aspose.Word by referring the word template file(.dotx file).

In that template file we are using “Mail Merge Filed” and while generating the word document using Aspose.Word, we are assigning values to Mail Merge fields and after successful generation of document we are storing that document file in SharePoint document Library.

We have a scenario that we need some MailMerge fields to be updated later after some database operation and after that hose will be updated in the document.

For Example:
I have following fields in template File:

«TableStart:TestInfo»
«testname»
«TableEnd:TestInfo»
«TableStart:CommentInfo»
«comment»
«TableEnd:CommentInfo»

While creating the document we are updating the TestInfo table with test name.
Also I am clearing the unused regions with the following code:
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions;

After successful geneartion of the document by using Aspose.Word, we are uploading that document to Documnt Library.

However my requirement is after some database operation, I want that “comment” filed need to be updated with the data reading from the database.
However I am facing difficulties here in getting those mail merge fields and also I am confused how to update the same also using Aspose.Word.

Could you please let me know whether we can achieve the same using Aspos.Word or not?

Could you please help me in achieving the same?

Please revert in case of any issue.
Thanks,
Rajesh

Hi Rajesh,
What I have understood from your post is that You are executing the mail merge and removing unused regions successfully. Now you want to populate removed fields i.e. ‘comment’ field in your case.
Removed fields will not be available for future mail merges. If you want to use some fields later, you should keep those fields intact instead of removing them. You can also add new merge fields before executing second mail merge.
Best Regards,

Hi Muhammad,

Thanks for your reply on this.

We are using the remove mail merge option as if we are not assigning any values during document generation, then those fields are coming as originally present in the template like <<TableStart:CommentInfo>> <<commnet>> like this. So to avoid this we are using the remove/clean up option.

Could you please let us know, if there is any other option available in Aspose.Word, so that we can hide those unused merge fields and later we can use those and we can also make visible at later point.

Please revert in case of any issue.
Thanks,
Rajesh

Hi Rajesh,

Thanks for your inquiry. I think, you can achieve this by enclosing region inside an IF field.

{ IF { MERGEFIELD "Flag" } = "hide" "true part of IF" "mail merge region" }

I hope, this helps.

Best regards,