Free Support Forum - aspose.com

MergeFields not disappearing

Good Afternoon,

I have created a MailMerge document but one of the fields has a value that is part of another table in the dataset. I have added a tablestart and tableend around the specific cell as it is nested inside another table.

The result displays without any issue if there is some valid XML data to return, however if the result is false the cell should be hidden, but its still showing albeit a blank cell.

Is there a way to ensure that this can be hidden?

Thanks in advance to anyone that can stop be from banging my head against a wall :slight_smile:

Carl

Merge.png (2.5 KB)

@TechDev2019,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words for .NET 19.11 generated output DOCX file showing the undesired behavior
  • Your expected DOCX file showing the desired output. You can create this document by using MS Word.
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

1 Like

Hi @awais.hafeez due to the nature of the business I wont be able to provide any source code. The application is extremely complex, it consists of 25 solutions, spanned over 240 c# projects to put it into perspective and there’s so much going on that I dont think you would be able to replicate it. I receive the desired output when it is outside of a table, however when it is included as a separate cell, from within another table, the value is displayed when there is valid XML, but if there isnt any to display ie the outcome is “nil = true” the cell remains, but is blank.

I’ll put together some examples so you can see what I am referring to and hopefully that is enough for you to provide some advice, and I completely understand if you need more, but that’s as good as I can provide, I’m sorry. :frowning_face:

@TechDev2019,

I think, inside FieldMergingCallback events you can mark such empty mergefield value Cells with Bookmarks and latter remove those Cells after the completion of mail merge. Here is how you can identify the Cell by Bookmark’s (or Field’s) name:

Cell cell = (Cell) doc.Range.Bookmarks["tempBM"].BookmarkStart.GetAncestor(NodeType.Cell);
if (string.IsNullOrEmpty(cell.ToString(SaveFormat.Text).Trim()))
    cell.Remove();

Sure, we will wait for your any further input on this topic.

Hi @awais.hafeez I have received confirmation from the business that they are happy with the workaround that we have provided, so I’ll leave it there for the time being. Thank you for all of the help that you provided so far.

@TechDev2019,

Thanks for your feedback. It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

1 Like