We have recently replaced the Office Interop assemblies with Aspose for some Mail Merge operations. The main documents used in the merge are maintained by our clients, and the application performs Mail Merge with a DataTable as the data source (the data table is the result of a stored procedure). Our users have now encountered a problem where their conditional return “Unkown opcode for conditional” when the mergefield values are empty.
I isolated one of the templates and tested it with the overloaded MailMerge.Execute(string[], object[]) method, and the results are similar.
Here’s the source code
Document templateDoc = new Document(wordFileName);
String[] fieldnames = new String[] { "Legal_Name1", "Cmb_Effective_Date", "ODL_1", "ODL_2", "ODL_3", "ODL_4", "ODL_5", "ODL_6", "ODL_7", "ODL_8", "ODL_9", "ODL_10", "ODL_11", "ODL_12", "ODL_13", "ODL_14", "ODL_15", "ODL_16", "ODL_17", "ODL_18", "ODL_19", "ODL_20" };
object[] fieldvalues = new object[] {"ABC Company, Inc.", "01/01/2010", "First Requirement", "Second Requirement", "Third Requirement", "Fourth Requirement", "Fifth Requirement", "Sixth Requirement", String.Empty, null, null, null, null, null, null, null, null, null, null, null, null, null };
templateDoc.MailMerge.UseNonMergeFields = true;
templateDoc.MailMerge.Execute(fieldnames, fieldvalues);
templateDoc.Save(outputFileName);
I have included the main document, if it helps debug the problem.
Thanks