Free Support Forum - aspose.com

Double quotes and IF fields in 8.1

Hello,

I've seen different behavior when combining the conditional field, e.g.

{ IF { MERGEFIELD CONDITIONALFIELD } <> "" "Some text" "Other text" }

When the value of CONDITIONALFIELD has white spaces, e.g. "VALUE 1", sometimes the engine of Aspose.Words introduces the double quote at the beginning and end, but other times it doesn't happen, causing a syntax error in the IF field.

Why did this happen?

Thank you.

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. The value which contains white spaces should be double quoted, otherwise how to know where condition starts and where value ends, values and conditions are separated by white space in IF fields.

I cannot reproduce the problem on my side using the latest version of Aspose.Words. I use the following code for testing:

Document doc = new Document(@"Test\in.doc");

doc.MailMerge.Execute(new string[] { "CONDITIONALFIELD" }, new string[] { "Test Test 1" });

doc.Save(@"Test\out.doc");

Best regards,

Correct. Aspose.Words removes merge fields, replacing them with data source values. If a merge field is nested, for example is a part of an IF field conditional expression, and its value contains whitespace, it should be enclosed into double quotes, otherwise the expression will be broken. Could you please provide a sample document and code that causes an error?

Thanks.

Yes, you're right

But my question is, writes Aspose.Words 8.1 the double quotes automatically? This is the proper functioning? or should I write the double quotes manually?

Thank you.

Yes, Aspose.Words writes double quotes automatically if mergefield is nested into IF field.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Best regards,

...and if it is really needed. For example, if a merge field is already enclosed in double quotes, there is no need to enclose the value. So the behaviour is flexible. Please let us know if you encounter an issue such as a broken expression or something.

And, what happens when the value of merge field is an empty string?

thank you

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. In case if merge field is enclosed with double quotes, then just an empty string will be inserted. If merge field is not enclosed with double quotes then double quotes will be added. Here is an example:

{ IF { MERGEFIELD test } = "test" "true" "false" }

{ IF "{ MERGEFIELD test }" = "test" "true" "false" }

If you put an empty string as a value of “test” merge field, the output will look like the following:

{ IF "" = "test" "true" "false" }

{ IF "" = "test" "true" "false" }

You can download the evaluation version of Aspose.Words and check on your side all cases. Please let me know in case of any issues.

Best regards.

I just found the problem. It's in the nested IF fields.

{ IF {MERGEFIELD FIELD1 } = "TEXT1" "TRUE { IF {MERGEFIELD FIELD2 } <> "TEXT2" "TRUE" "FALSE" }" "FALSE"}

In the second IF Aspose.Words doesn't write de dobles quotes.

Greetings.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for reporting this problem to us. I managed to reproduce it on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards.

Hello

I have found another problem, Undefined Bookmark

It occurs when you give a numeric value to FIELD1.

{ IF { MERGEFIELD FIELD1 } = "A" "TRUE" "FALSE" }

Thank you.

The issues you have found earlier (filed as 14048;14989) have been fixed in this update.


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