Hello Dmytro,
Thank you for your assistance.
Through testing, I have confirmed the issue regarding the failure to read the IF field value. Additionally, I discovered that after populating the MergedField value, saving the result document, and reopening it to read (as shown in the code snippet below), the value can be retrieved via ifField.FieldText. However, the result obtained is "Dmytro * MERGEFORMAT " instead of just "Dmytro".
- Code: Select all
Document document = new Document();
document.LoadFromFile(path + "If field example.docx");
String[] fieldName = { "FormattedName" };
String[] fieldValue = { "Dmytro" };
document.MailMerge.Execute(fieldName, fieldValue);
document.IsUpdateFields = true;
MemoryStream memoryStream = new MemoryStream();
document.SaveToStream(memoryStream, FileFormat.Docx2019);
document = new Document();
document.LoadFromStream(memoryStream, FileFormat.Auto);
Body body = document.Sections[0].Body;
for (int i = 0; i < body.ChildObjects.Count; i++)
{
if (body.ChildObjects[i].DocumentObjectType == DocumentObjectType.Paragraph)
{
Paragraph paragraph = (Paragraph)body.ChildObjects[i];
for (int j = 0; j < paragraph.ChildObjects.Count; j++)
{
if(paragraph.ChildObjects[j].DocumentObjectType == DocumentObjectType.Field)
{
Field field = (Field)paragraph.ChildObjects[j];
if (field.Type == FieldType.FieldIf)
{
IField ifField = (IField)field;
String fieldText = field.FieldText;
}
}
}
}
}
I have logged both identified issues in our tracking system under ticket number SPIREDOC-11845. Our development team will conduct a thorough investigation and work on a resolution. We will keep you updated on the progress.
Sincerely,
Amy
E-iceblue support team