Hello,
Hi Karel,
Thanks for your inquiry. Yes, you can mix mail merge fields with mail merge fields having ‘Mustache’ syntax. I have created two sample documents and have attached to this post for your kind reference. Please check the following code example.
Document doc = new Document(MyDir + “MailMergewithRegion.docx”);
doc.MailMerge.UseNonMergeFields = true;
DataSet ds = new DataSet();
ds.ReadXml(MyDir + "dataset.xml");
doc.MailMerge.ExecuteWithRegions(ds);
doc.Save(MyDir + "MailMergewithRegion.Out.docx");
doc = new Document(MyDir + "SimpleMailMerge.docx");
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.Execute(new string[] { "ShortName"}, new string[] { "Short Name" });
doc.Save(MyDir + "SimpleMailMerge.Out.docx");
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
I suggest you please read following documentation link for your kind reference.
http://www.aspose.com/docs/display/wordsnet/Mail+Merge+using+%27Mustache%27+Template+Syntax
Thank you,
Hi Karel,
Thanks for your inquiry.
karel.bem:
we finally solved the issue, the problem was in code:
myDoc.MailMerge.FieldMergingCallback = new HandleMailMergeFields(highlightMailMergedParts);
It is nice to hear from you that your problem has been solved. Yes, you achieve your requirement by implementing IFieldMergingCallback interface.
karel.bem:
Do you know if this is a known issue that this custom formatting and the new Mustache syntax cannot work together?
This is not an issue. Please check the code example and attached documents in my previous post. It would be great if you please share your input document along with sample code example to reproduce the issue which you are facing. We will then provide you more information about your query.
Thank you, we have solved the second issue as well (it was our custom code that needed to be changed)
Hi Karel,
{ MERGEFIELD Test * Upper \b Start \f After * MERGEFORMAT }
{MERGEFIELD NumberValue # “#,##0.00”}
Mail Merge with Mustache syntax
{{ Test * Upper \b Start \f After * MERGEFORMAT }}
{{ NumberValue # “#,##0.00” }}
Hope this answers your query. Please let us know if you have any more queries.
Thank you for another advice.
<span lang=“EN-GB” style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;mso-fareast-language:
EN-CA”><o:p></o:p>
Hi Karel,
Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.10.0) from here and let us know how it goes on your side. Perhaps, you are not using the correct field name while doing mail merge. If the problem still remains, please attach your input Word document here for testing. I will investigate the issue on my side and provide you more information.
Hi,
Hi Karel,
Thanks
for your inquiry. I have created a template document with following two mail merge fields. Please check the attached documents.
{{ PremiumEstimated1 # “#,##0.00”}}
{{ PremiumEstimated2 # “#,##0.00”}}
Following code example perform the mail merge twice. In IFieldMergingCallback.FieldMerging the field codes are as follow. There is no issue while performing mail merge.
MERGEFIELD “PremiumEstimated1” # “#,##0.00”
MERGEFIELD “PremiumEstimated2” # “#,##0.00”
Please note that if your implementation does not perform merge merge for all fields, the mail merge fields which are not merged are convert to normal merge fields in output document. For example, if there is another mail merge field named PremiumEstimated3 and this field is not merged, the output document will have «PremiumEstimated3» field with field code { MERGEFIELD “PremiumEstimated2” # “#,##0.00” }.
Document doc = new Document(MyDir + "Test40.docx");
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldTest40();
doc.MailMerge.Execute(new string[] { "PremiumEstimated1" }, new object[] { 123456 });
doc.MailMerge.Execute(new string[] { "PremiumEstimated2" }, new object[] { 123456 });
doc.Save(MyDir + "Out.docx");
private class HandleMergeFieldTest40 : IFieldMergingCallback
{
///
/// This is called when merge field is actually merged with data in the document.
///
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
if (e.FieldValue != null)
{
Console.WriteLine(e.Field.GetFieldCode() + " : " + e.FieldValue);
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
builder.Write(e.FieldValue.ToString());
e.Text = "";
}
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
// Do nothing.
}
}
Hope this answers your query. If you still face problem, please share following detail for investigation purposes.
- Please attach your input Word document.
- Please
create a standalone/runnable simple application (for example a Console
Application Project) that demonstrates the code (Aspose.Words code) you used to generate
your output document - Please attach the output Word file that shows the undesired behavior.
- Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.
Thank you,
Hi Karel,
Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.