Hello,
I have a small problem with the quotation marks («»). When I use Aspose.Word for .net to merge database fields with a Word document, the text after the quotation marks doesn’t appear in the Word document after the merge. Do you have a solution?
Thank you and have a good day.
@sylvain.couture Could you please attach your template, simple code that will allow us to reproduce the problem and the problematic output? WE will check the issue and provide you more information.
The problem occurs in the if statements when the quotation marks are inside the variable. Here’s an image attached.
@sylvain.couture It is normally is not allowed to use double quotes in IF field values. And the only way to have a double quite in the IF field is using an embedded field like this { QUOTE 34 } . This is MS Word limitation. You can try using IFieldMergingCallback to resolve the problem.
Document doc = new Document("C:\\Temp\\in.docx");
doc.MailMerge.UnconditionalMergeFieldsAndRegions = true;
doc.MailMerge.FieldMergingCallback = new QuoteResolver();
doc.MailMerge.Execute(new String[] { "condition", "desc1", "desc2" },
new String[] { "true", "The \"first\" description", "The \"second\" description" });
doc.Save("C:\\temp\\out.docx");
private class QuoteResolver : IFieldMergingCallback
{
public void FieldMerging(FieldMergingArgs args)
{
string fieldValue = (string)args.FieldValue;
if (!fieldValue.Contains("\""))
return;
String[] parts = fieldValue.Split('\"');
DocumentBuilder builder = new DocumentBuilder(args.Document);
builder.MoveToField(args.Field, false);
for (int i = 0; i < parts.Length; i++)
{
builder.Write(parts[i]);
if (i < parts.Length - 1)
builder.InsertField("QUOTE 34");
}
args.Text = "";
}
public void ImageFieldMerging(ImageFieldMergingArgs args)
{
// Do nothing.
}
}