Hello,
Thanks for your inquiry!
I created a field “{ IF { MERGEFIELD myField } <> "66" "TRUE" "FALSE" }” to the Word file and mail merge it with the latest
Spire.Doc V9.4.12. Both the IF field and the Merge field can merge correctly. I also attached my testing code for your reference.
- Code: Select all
//{ IF { MERGEFIELD myField } <> "66" "TRUE" "FALSE" }
Document newDoc = new Document();
Section section = newDoc.AddSection();
Paragraph paragraph = section.AddParagraph();
//The IF field
IfField ifField = new IfField(newDoc);
ifField.Type = FieldType.FieldIf;
ifField.Code = "IF ";
paragraph.ChildObjects.Add(ifField);
//the merge field
MergeField mergeField = new MergeField(newDoc);
mergeField.Type = FieldType.FieldMergeField;
mergeField.Code = "MERGEFIELD myField";
mergeField.FieldText = "myField";
paragraph.ChildObjects.Add(mergeField);
TextRange textRange = new TextRange(newDoc);
textRange.Text = "<> \"66\" \"TRUE\" \"FALSE\" ";
paragraph.ChildObjects.Add(textRange);
FieldMark mergeFieldMark = new FieldMark(newDoc, FieldMarkType.FieldEnd);
mergeField.End = mergeFieldMark;
paragraph.ChildObjects.Add(mergeFieldMark);
FieldMark ifFieldMark = new FieldMark(newDoc, FieldMarkType.FieldEnd);
ifField.End = ifFieldMark;
paragraph.ChildObjects.Add(ifFieldMark);
//save template
string result = "myField.docx";
newDoc.SaveToFile(result, FileFormat.Docx2013);
//merge
Document doc = new Document();
doc.LoadFromFile(result);
var FieldNames = new string[] { "myField" };
var FieldValues = new string[] { "aaa" };
doc.MailMerge.Execute(FieldNames, FieldValues);
doc.IsUpdateFields = true;
result = "myFieldResult.docx";
doc.SaveToFile(result, FileFormat.Docx2013);
If you were not using the latest version, I recommend that you can try the latest version with my code again. If the issue still exists, please provide us with your target framework, system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese) for reference. Thanks in advance.
Sincerely,
Marcia
E-iceblue support team