We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

OpCode-Error in Mailmerge of Condition-Fields

In several templates an error appears when OpCode condition tests.
It’s probably because of the lack of spaces between the parentheses
and the following comparison operators.
Is there a way to fix existing templates programmatically ?

Hi György,

Thanks for your query. It would be great, If you share sample document and code for investigation purposes.

Hello,
thanks for the quick response.
Attached as desired template, which triggers an opcode error.

Hi György,

Thanks for sharing the doc file. I cannot reproduce the problem on my side using the latest version of Aspose.Words for .NET 10.7.0. Please find the generated document in attachment.

Hi
György,


Thanks for your request. First of all, please note that a Word document stores IF fields in the following format.


and this structure can also be seen below in hierarchical form using the demo project “DocumentExplorer”, which ships with the Aspose.Words installer.


Considering this structure, you can easily edit the field code programmatically e.g:

Document
doc = new Document(@“C:\test\if.docx”);

NodeCollection fields = doc.GetChildNodes(NodeType.FieldStart,
true);
foreach (FieldStart start in
fields)
{
if
(start.FieldType ==
FieldType.FieldIf)
{
Run
fieldCode = start.NextSibling
as Run;
fieldCode.Text = " IF 2 > 0
“true” “false”"
;
}
}

doc.Save(@“C:\test\Ifs.docx”);

Also, I have attached here if.docx document for you to play with.

Secondly, I was unable to find any such OpCode error in your provided document. I managed to successfully update the fields in your document with Aspose.Words v10.7.0.

If we can help you with anything else, please feel free to ask.

Best Regards,

Thank you, exactly what I needed.