Hi,
We use Aspose.Words to generate word report. Currently we use v9.2, but we want to upgrade to v9.8. When we tested report generation using v9.8, the generation failed. By debugging, I found the exception “object reference not set to an instance of an object” was thrown, when calling Document.MailMerge.Execute(string[] fieldNames, object[] values) method. The callstack is below:
at x4adf554d20d941a6.x5c28fdcd27dee7d9.get_x9a05d8dab0f0619f() at x4adf554d20d941a6.x61c61e304d8f82bf.xef8721f06e48b9f3() at x4adf554d20d941a6.x61c61e304d8f82bf.x408f4b7efc86fd49() at x4adf554d20d941a6.xeefdffd909e695da.x408f4b7efc86fd49() at x4adf554d20d941a6.xeefdffd909e695da.xc3819e13f60dd8e6(Boolean xfad304b5f8f3bb5b) at x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98(Document x3664041d21d73fdc, xdeb77ea37ad74c56 xdfde339da46db651) at Aspose.Words.Document.UpdatePageLayout() at xfbd1009a0cbb9842.xe70a81b27884f7a0.xb333e1e6c01c2be2() at xfbd1009a0cbb9842.xbf9ddf72e1283af9.x18dfca7c5fd2402f() at xfbd1009a0cbb9842.xfedf115fd9c03862.xdd6cf0348a23f220(xcf417e2db4fe9ed3 xe00c282e1a49fcfb) at xfbd1009a0cbb9842.xfedf115fd9c03862.x118a2acc122f2bb3() at xe86f37adaccef1c3.xc5c3f438428cb03b.xdeeb682062ef79a5() at xe86f37adaccef1c3.xc5c3f438428cb03b.xd5da23b762ce52a2(MailMerge x2a99de81295e7f29, IMailMergeDataSource xef1769c4fe6ae4ca, Boolean xc9c7b90943167aed) at Aspose.Words.Reporting.MailMerge.Execute(IMailMergeDataSource dataSource) at Aspose.Words.Reporting.MailMerge.Execute(String[] fieldNames, Object[] values) at ConsoleApplication2.Program.Main(String[] args) in C:\Documents and Settings\sheng-ye\My Documents\Test For Markups\Test For Markups\ConsoleApplication2\Program.cs:line 52
It is very strange. It works finely in old version(9.2), while failed in newer version.
The code is below:
try
{
License license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.lic");
Document doc = new Document(@"DEDirectPromiseMasterTemplate.doc");
Dictionary <string, object> dataSource = new Dictionary <string, object> ();
foreach(string fieldName in doc.MailMerge.GetFieldNames())
{
if (dataSource.ContainsKey(fieldName))
continue;
if (fieldName.Contains("$"))
{
dataSource.Add(fieldName, true);
}
else if (fieldName == "BITAG")
{
dataSource.Add(fieldName, new DateTime(2011, 12, 31));
}
else if (fieldName == "ZINS_IA" || fieldName == "ABWZINS" || fieldName == "INFL_IA")
{
dataSource.Add(fieldName, 0.25);
}
else
{
dataSource.Add(fieldName, 99999);
}
}
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
doc.MailMerge.Execute(dataSource.Keys.ToArray(), dataSource.Values.ToArray());
doc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob();
DataTable table = new DataTable("Signature");
table.Columns.Add("MySignature");
table.Rows.Add(new object[]
{
"MySignature2.bmp"
});
DataTable table1 = new DataTable("Signature1");
table1.Columns.Add("MySignature");
table1.Rows.Add(new object[]
{
"MySignature2.bmp"
});
doc.MailMerge.ExecuteWithRegions(table);
doc.MailMerge.ExecuteWithRegions(table1);
// doc.UpdateFields();
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
doc.Save(string.Format("results_{0:yyyyMMddHHmmss}.doc", DateTime.Now));
Console.WriteLine("Doc Is Saved");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
The attachement is the template. Can anybody help me to have a look at this issue?