Free Support Forum - aspose.com

New MERGEFIELD IF functions

I’m struggling with the new MERGEFIELD functions. I tried the following things:


{ MERGEFIELD
{IF {MERGEFIELD
OrderTypeId } =6}<span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;line-height:150%;
font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-bidi-font-family:“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:
DE;mso-bidi-language:AR-SA;mso-no-proof:yes”> LanguageTarget * MERGEFORMAT }

<span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:
12.0pt;line-height:150%;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;line-height:150%;
font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-bidi-font-family:“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:
DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;line-height:150%;
font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-bidi-font-family:“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:
DE;mso-bidi-language:AR-SA;mso-no-proof:yes”>{IF { MERGEFIELD
OrderTypeId } =6 “Translation”
“Other” * MERGEFORMAT }

<span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:
12.0pt;line-height:150%;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;line-height:150%;
font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-bidi-font-family:“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:
DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;
line-height:150%;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:DE;mso-bidi-language:AR-SA;mso-no-proof:yes”>{ IF 5 = 5 “true”
“false”}
<span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:
12.0pt;line-height:150%;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span lang=“DE” style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;line-height:150%;
font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-bidi-font-family:“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:
DE;mso-bidi-language:AR-SA;mso-no-proof:yes”><span style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;
line-height:150%;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:DE;mso-bidi-language:AR-SA;mso-no-proof:yes”>
Non of those work. No idea why? I’ve attached the word file as an example.

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

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words (8.2.1).

{ MERGEFIELD {IF {MERGEFIELD OrderTypeId } = 6} LanguageTarget \* MERGEFORMAT } – works fine

{IF { MERGEFIELD OrderTypeId } = 6 "Translation" "Other" \* MERGEFORMAT } – works fine, there should be white spaces before and after comparison operator

{ IF 5 = 5 "true" "false"} – works fine

Best regards,

Thanks for the quick response. I’m using 8.2.1.0


1:
{ MERGEFIELD {IF {MERGEFIELD OrderTypeId } = 6} LanguageTarget * MERGEFORMAT }
Only {MERGEFIELD OrderTypeId } gets evaluated, but that is the only thing here.

2:
{IF { MERGEFIELD OrderTypeId } = 6 “Translation” “Other” * MERGEFORMAT }
Same here

3:
{ IF 5 = 5 “true” “false”}
Nothing happens at all. This is inside a MERGEFIELD TableStart:Data Construction. Did you try out my wordfile or just the queries?

Regards

Remy

Hi

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

Thanks for your request. Could you please attach your output document here for testing? I will check the problem on my side and provide you more information.

Best regards,

It’s attached in the first post.

Hi

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

Thank you for additional information. Even MS Word does not update fields like

{ MERGEFIELD {IF {MERGEFIELD OrderTypeId } =6} LanguageTarget \* MERGEFORMAT } (“Try 1”)

Ctrl+A and then press F9 to update fields. I think in this case it is better to use construction like the following { IF {MERGEFIELD test1} = 6 "{MERGEFIEL test2}" ""} it works fine on my side.

I use the following code:

Document doc = new Document("Filename_Customer_Bill.doc");

doc.MailMerge.ExecuteWithRegions(GetData());

doc.Save("out.doc");

private DataTable GetData()

{

// Create data table

DataTable table = new DataTable("Data");

table.Columns.Add("OrderTypeId");

// Add some dummy data.

table.Rows.Add(new object[] { "6"});

table.Rows.Add(new object[] { "5"});

return table;

}

Also I sent the input and the output documents to your e-mail.

As you can see “Try 2” and “Try 3” work fine.

Best regards,

Thanks again for the effort. But you got me completely confused now.


Lets start with try 3:

{ IF 5 = 5 “true” “false”}

I would expect that after the mailmerge, I only see true in the final document. Same with try 2, there it should be either Translation or Other. No? With all other MERGEFIELD fields I get the value of the field hardcoded in the document and the actual MERGEFIELD construct is gone after the mailmerge.

But here, I still have the MERGEFIELD stuff. In Try 2, the {MERGEFIELD OrderTypeId} is also replaced with 6 in the final document, but I actually need the final result of the IF statement to be in the document, e.g. Translation.

Did I miss something here?

Hi

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

Thanks for your request. Yes you are right, after update this field { IF 5 = 5 "true" "false"} you will see just “true” in the final document. Please see the attached screenshot. Also I attached simplified input and output documents here. Please try using the code from my previous post.

Best regards,

I just made a screenshot of your out.doc and I still have the MERGEFIELD fields in there. The “true” is not hardcoded. We have to send these files to clients, so there should only be content in there, but no MERGEFIELD stuff anymore.

The inner MERGEFIELD from try 2 is hardcoded to 6 and 5. That is kinda what I need, but I need the result of the evaluation of the IF clause to be hardcoded. Do you see my point?

Hi

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

Thank you for additional information. Please just open your document using MS Word and press Alt-F9 to hide/show the field code.

Best regards,

Sorry to be such a pain the neck, but as I said, the point was NOT to have the field codes in there anymore, just the final result.

It’s not a matter of using word and pressing F9. I cannot send the file with the fieldcodes in there. Do you get my point?
Currently I still have the { IF } stuff in the file. I know if I press F9 it is replaced by the result, but I need the file WITHOUT the { IF } stuff and with just the result from the merge. But I guess what you are trying to avoid saying is that this is not possible, no?

Hi

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

Thanks for your inquiry. Please follow the link to learn how to achieve what you need:

http://www.aspose.com/community/forums/222671/removing-ifs-from-resolved-document/showthread.aspx#222671

Best regards,

You’re da man! :slight_smile:


That was exactly what I was looking for. Sorry, didn’t know that needs an extra step.