Free Support Forum - aspose.com

Syntax error when using AND

Hello,



I see some unexpected results when using an AND field in the document. When running the code with the attached document the results are different depending on the OS you’re working on and if a mailmerge is executed.



template.getMailMerge().execute(new String[] { “dummy” }, new Object[] { “dummy_value” });

BookmarkCollection bookmarks = template.getRange().getBookmarks();

for (Bookmark bookmark : bookmarks) {

System.out.println(bookmark.getName() + " " + bookmark.getText());

}



Result on Windows:

Test 1

Test4 !Syntax error



Result on Linux (Ubuntu):

Test !Syntax error

Test4 1



The difference is in the separator of the AND operator. Windows uses ;

Linux uses ,



If no mailmerge is executed than ; can be used on both OS-es.



This was found using Aspose 11.3.0 and reproduced with 11.8.0 and 11.9.0

Hi Ischa,


Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behavior as MS Word do. In your case, please read Run node between FieldStart and FieldEnd nodes and update the Run node’s text on the according to Operating systems. Please read following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsjava/FieldStart
http://www.aspose.com/docs/display/wordsjava/FieldEnd

Hi Tahir,



I’m not sure if I understand you correctly:

I should modify the Run text depending on the OS our application runs? And depending on whether a mailmerge is executed or not?

If the mailmerge is not executed there is no need to change the text of a Run. Only when a mailmerge is executed the behavior is not as expected.

Hi Ischa,


Thanks for your inquiry. Could you please attach your input Word template (with mail merge filed and =AND…) here for testing? Please share how you are using mail merge with formula field (=AND(1;1))? I will investigate the issue on my side and provide you more information.

Hi Tahir,



I attached the document with my first post. The merge fields do not have te be present in the document. Just use dummy values as stated in my first post. But a mailmerge should be executed to encounter the problem. Run the same code on different platforms (windows and linux) and different behavior is seen.

Hi Ischa,


Thanks for sharing the details.
imooren:

If no mailmerge is executed than ; can be used on both OS-es.

I have used the following code snippet to test this issue at Windows 7 and Ubuntu. The output document shows the default behavior in MS Word. Please find the output document in attachment.

Document doc = new Document(MYDir
  • “syntaxerror.doc”);

doc.updateFields();

doc.save(MYDir + "AsposeOut-Java.docx");

I have tested the scenario with and without mail merge and got the same output files. It would be great if you please share your code along with input/output documents here for investigation purposes. Are you using syntaxerror.doc as input document?