Error! Unknown op code for conditional when using double quotes in if mergefield

We have in our word document a mergefield in an if to test if it is empty or not:
{ IF "{MERGEFIELD test}" <> "" "if condition succeeded"}

We use a FieldMergingCallback so that we can insert as html.

When the value of the mergefield ‘test’ contains double quotes, we get the following error on the created document: Error!
Unknown op code for conditional.

If it’s not inserted as html the problem does not occur. So it’s a problem to use mergefields that we want to render as html in an if structure if it has double quotes.

How can this be fixed please?

Hi Ann,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-13199. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-13199) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.


I’ve tested it again and the error is gone but I don’t get the functionality that is needed in my scenario.

{ IF "{MERGEFIELD test}" <> "" "if condition succeeded"} should print “if condition succeeded”, but it prints out the part inside the quotes from the test variable. So the test variable is “test with “quotes”” and I get this on the document: “quotes”. See example in attachment.

I also found an issue when the mergefield with quotes is not in the condition of the if, but in the result. Then it prints out everything before the first quote. If it starts with quotes it prints nothing.

{ IF "test" = "test" "{MERGEFIELD test3}" } prints out “variable with” instead of “variable with “quotes” as output from if”. See also in test probject as attachment.

Hi Ann,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert the string with double quote inside IF field using MS Word and update the field, you will get the same output.

You need to replace double quote (") with " or with {QUOTE 34} field inside IF field. Please check following modified code snippet. Hope this helps you.

public boolean getValue(String fieldName, Object[] fieldValue) throws Exception
        case "test" : fieldValue[0] = "test with {QUOTE 34}quotes{QUOTE 34}"; break;
        case "test2" : fieldValue[0] = "test without quotes"; break;
        case "test3" : fieldValue[0] = "variable with {QUOTE 34}quotes{QUOTE 34} as output from if"; break;
    for (Object fieldVal : fieldValue)
    return true;
public void fieldMerging(FieldMergingArgs args) throws Exception
    DocumentBuilder builder = new DocumentBuilder(args.getDocument());
    builder.moveToMergeField(args.getDocumentFieldName(), true, false);
    String fieldValue = (String) args.getFieldValue();
    String[] str = fieldValue.split("\\{QUOTE 34\\}");
    for(int i = 0; i < str.length; i++)
        builder.insertHtml(str[i], false);
        builder.insertField("QUOTE 34");


Thanks for your help. I still have some problems when I want to insert html code. Because insertHtml will be used for example for variables like "
Text with “quotes” and “style” in html
". In the html tags there are also quotes who can not be inserted with insertField(“QUOTE 34”). The result is something like this: ““font-family:Verdana;”>Text with "quotes"and “style"in html” instead of only the text "Text with "quotes"and "style"in html” with the needed style. After the (second) quote there is no space, even the space is present in the variable and put in the insertHtml method. How can we fix this? Thanks!

See again my example project with the documents included.

Hi Ann,

Thanks for your inquiry. As share in my previous post, Aspose.Words mimics the same behavior as MS Word does. If you insert the string with double quote inside IF field using MS Word and update the field, you will get the same output.

Could you please share your input and expected output Word documents here for our reference? We will then provide you more information about your query along with code.


As attachment my:
- input document: sjabloon-test.doc
- output document: sjabloon-test-output.doc
- expected output document: sjabloon-test-expected-output.doc

Thanks for taking a look at it.

Hi Ann,

Thanks for sharing the detail. You are facing the expected behavior of Aspose.Words. You are inserting the double quote inside IF field condition and result. In this case you need to workaround around this issue by replacing double quote with {QUOTE 34} field. Please check following link for your kind reference.
IF statement with embedded double quotes

You are also inserting the html styles which contain the double quote. In this case, you can workaround this issue by using following approach:

  1. Replace Html contents (text that display in browser) with text QUOTE. See the following highlighted text below.
  2. Replace QUOTE with double quote (") using Document.Range.Replace method before saving the document.

Text with QUOTEquotesQUOTE and QUOTEstyleQUOTE in html