Brand spanking new to Aspose. I inherited a project where I need to add an IF statement and have not a clue how to do this or even where to go to find out.
I need to add an IF Rates Table has no rows, do not show the following table. Could someone point me in the right direction?
Service Description |
Per Hour Rate |
UOM Rate |
UOM |
«TableStart:Rates»«ServiceDesc» |
«HourRate» |
«UOMRate» |
«UOM»«TableEnd:Rates» |
Is this an Aspose thing or a Microsoft Word thing?
Sorry for being obtuse. I’m usually a web developer…I’ve never worked with these technologies.
@matthew2 You can wrap the whole region into IF field condition and then after executing mail merge with regions also execute simple mail merge to evaluate the condition.
Also, you can set MailMergeCleanupOptions.RemoveEmptyTableRows
in this case empty rows will be removed from the document. Or if mail merge is not executed with empty data table for the region, you can set MailMergeCleanupOptions.RemoveUnusedRegions
.
https://reference.aspose.com/words/net/aspose.words.mailmerging/mailmergecleanupoptions/
Excellent! I’m halfway there. What is the syntax to determine if a table has rows?
Something like IF TableStart:Rates.Count > 0
but it’s not that…
@matthew2 In this case you can use another parameter with data count. For example:
IF RatesCount > 0
collect data and use mail merge to pass this count:
template.MailMerge.Execute(new string[] { "RatesCount" }, new object[] { dataCount });
Also, you can check FieldIf Class | Aspose.Words for .NET and Insert Fields in C#|Aspose.Words for .NET
I feel like I am close but I am missing a step. I have the following code now:
{ MERGEFIELD RateCount }
{ IF RateCount = 0 “zero” “positive integer” }
But my results end up like so:
0
positive integer
What am I missing?
Never mind. I answered my own question. I needed an extra set of curly braces:
{ MERGEFIELD RateCount }
{ IF { RateCount } = 0 “zero” “positive integer” }
@matthew2 It is perfect that you managed to resolve the problem.