When MailMerging fields with custom formatting, and CultureInfo settings that include
Culture.NumberFormat.Number/CurrencyDecimalSeparator = ‘,’ (Comma)
Culture.NumberFormat.Number/CurrencyGroupSeparator = ‘.’ (Dot)
A MergeField such as
{ MERGEFIELD "fieldName1" \# "#.##0,00" }
where fieldName1 = 0, a MailMerge produces a result of ,00000 where 0,00 was expected.
A workaround is to pre-process the template, and replace the formatting.
if (fieldCode.Text.IndexOf("#.#")> 0)
{
fieldCode.Text = fieldCode.Text.Replace("#.#", "#,#");
}
if (fieldCode.Text.IndexOf("0,0")> 0)
{
fieldCode.Text = fieldCode.Text.Replace("0,0", "0.0");
}
This correctly produces a result of 0,00 after the mailmerge.
-
Now if we add an IF statement to this, such as
{ IF { MERGEFIELD fieldName1 } <> 0 "{ MERGEFIELD "fieldName1" \# "#.##0,00" }" "{MERGEFIELD "fieldName2" \# "#.##0,00" }" }
Where fieldName1 = 0 and fieldName2 = 500,00
The result is an “un-flattened” Mergefield with a value of
{ IF 0 <> 0 "0,00" "500,00" }
where a “flattened” value of 500,00 was expected.
-
Finally, if the merge adds arithmetic and complexity, it breaks. ie.:
{ ={ MERGEFIELD "fieldName1" }+{ MERGEFIELD "fieldName2" }+{ IF { MERGEFIELD fieldName3 } <> 0 "{MERGEFIELD "fieldName3" }" "{ MERGEFIELD "fieldName4" }" } \# "#.##0,00" }
Where FieldName1 = 1.000,00, FieldName2 = 500,00, FieldName3 = 0 and FieldName4 = 500,00
Produces a result of
{ =1.000,00+500,00+{ IF 0 <> 0 "0" "500,00" } \# "#.##0,00" }
Which, when printed produces
!Undefined Bookmark, 1.000,00
While stripping the Grouping char from the datasource, does produce a printable result.
Such a solution would however be unacceptable, as not all the templates define custom formatting rules, and sometimes merely reference the fieldName value as text.
Also, this solution produces 2000,00000 where 2.000,00 would be expected.
In short, how/when will we be able to inform Aspose (.Words) of which CultureInfo to use, so these “problems” can be avoided?
Respectfully, Jens Churchill.