How to remove If statement during Mail Merge using VB.NET

Hi,

I have a word template with a couple of IF statements. The if statement still exists after I used Aspose word to merge data.

Are there any methods to remove the IF statement in the result document?

I have attached the output file.

Hi Gangying,

Thanks for your query. It would be great if you please share your source document for investigation purposes.

Please read following documentation link for your kind reference. Hope this helps you. Please let us know if you have any more queries.

http://www.aspose.com/docs/display/wordsnet/How+to++replace+fields+with+static+text

Hi Tahir,

Thank you for your email. I can remove all IF statement block if the condition is false. But I cannot remove the image which is inside the if statement. The imgae appears at the bottom of the document three times. I have attached the sample project. You need to include the Aspose.Total.lic file to make it work.

Thank you,

Gangying

@wug

Hi Gangying,

Thanks for your query. I have added following function in FieldsHelper class. Please find the modified class in attachment.

Public Overrides Function VisitShapeStart(ByVal
shape As Shape)
As VisitorAction

' Remove the run if it is between the FieldStart and FieldSeparator of the field being converted.

CheckDepthAndRemoveNode(shape)

Return VisitorAction.Continue

End Function

Please let us know if you have any more queries.

Hi Tahir,

I have used the file to test my test file. It shows the opposite way. The image appears on the false condition and hides on the true condition. I have attache doc file.

Thank you,

Gangying

Hi there,


Thanks for your inquiry.

Actually, as long as you use the latest versions of Aspose.Words there is an in-built feature to remove the container IF field automatically. Please try using MailMergeCleanupOptions.RemoveContainingFields flag instead of the work around code above.

Thanks,

Hi Adam,

It works. I have already used the RemoveEmptyParagraphs in my code to remove the redundant blank line. Can I use both RemoveEmptyParagraphs and RemoveContainingFields at the same time to remove the blank line and IF statements?

With document

.MailMerge.CleanupOptions = Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs

.MailMerge.Execute(GetMergeFieldData)

.UpdateFields()

.Save(strFileName, SaveFormat.Doc)

End With

Thank you,

Gangying

Hi Gangying,


Thanks for your inquiry. Yes absolutely you can use any combination of these flags or all of them at once. Please see the code below:

.MailMerge.CleanupOptions = Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs Or Reporting.MailMergeCleanupOptions.RemoveContainingFields

Thanks,

Hi Adam, Tahir,

It solved my problem with all the comments by you and Tahir.

Thank you very much for your efforts.

Gangying

Hi Gangying,


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.