Is there a way to conditionally hide a row?

Hi there,

We use Microsoft word mail merge to create invoice templates and use Aspose to merge the template with data to create pdfs.

I
want to know if there’s a way to conditionally hide a row in a table
from the template. For example, I want to do something like “IF
Table1.column1 = ‘Discount’ THEN hide row”. The part I"m stuck with is
how do I tell Aspose to hide a row from the MS word template?

We’re on Aspose Words 13.4.0. Can you please advise?

Thanks,

Julia

This message was posted using Email2Forum by Shahzad Latif. (private)

Hi Julia,

Thanks for your inquiry. I think, there is no direct way that you can hide entire table row, instead you can use Row.Remove method to achieve this. I think, you can implement the following workflow to achieve this:

  1. Implament IFieldMergingCallback Interface.
  2. In the FieldMergingCallback event, insert a hidden Bookmark at a suitable place inside the Row(s) using DocumentBuilder. We just need to flag the Row(s) in Table that you want to remove.
  3. Now come to the statement right after ExecuteWithRegions method in the Main method.
  4. Move the cursor to the hidden Bookmark (i.e. inserted in Row(s) during MailMerge) using DocumentBuilder.
  5. Get the Row using GetAncestor method like: Row row = (Row)builder.CurrentNode.GetAncestor(NodeType.Row);
  6. Remove these rows.

Please let me know if I can be of any further assistance.

Best regards,