Hi Kris,
- Is it a handled exception? That is expected if the formula is invalid and in that case, the calculation will not be performed.
Nevertheless, can you try something like this:
var document = DocumentModel.Load("input.docx");
document.MailMerge.FieldMerging += (sender, e) =>
{
bool isEmpty = !e.IsValueFound || e.Value == null;
if (isEmpty)
{
Element parent = e.Field.Parent;
while (parent.ElementType != ElementType.Document)
{
if (parent.ElementType == ElementType.Field && ((Field)parent).FieldType == FieldType.Formula)
{
e.Inline = new Run(e.Document, "0");
break;
}
parent = parent.Parent;
}
}
};
document.MailMerge.Execute(new { Foo = (int?)null });
document.Save("output.docx");
- Unfortunately no, the calculation engine will take the whole instruction text of the formula field.
These switches (\b and \f) could be a part of some valid formula (for instance, referring to bookmark names) so in that case, such behavior would not be desirable.
You could perhaps handle this information in the FieldMerging event, but nevertheless, I believe that using the IF fields before or after the formula field would be a much simpler approach.
Regards,
Mario