Hallo Roman!
There ist still some slight performance issue in MailMerge. It is not
easy reproduced, but i have some test code to show it to you.
I have also a workaound. The template is attached.
Here ist the code (i use log4net for logging statements):
log.Debug("Bookmark Count = " +
doc.Range.Bookmarks.Count);
int i = 0;
foreach (Aspose.Word.Bookmark bookmark in
doc.Range.Bookmarks)
{
if ((i / 10) % 2 == 0)
{
bookmark.Text
= string.Empty;
}
i++;
}
log.Debug(“MailMerge Start”);
doc.MailMerge.Execute(new string[] {}, new object[]
{});
log.Debug(“MailMerge Stop”);
And here is the output:
2005-11-24 15:32:27,012 [2000] DEBUG Tests.Class1 - Bookmark Count = 486
2005-11-24 15:32:27,343 [2000] DEBUG Tests.Class1 - MailMerge Start
2005-11-24 15:32:29,206 [2000] DEBUG Tests.Class1 - MailMerge Stop
Now you see, that there are almost 2 seconds between MailMerge Start
and MailMerge Stop. In production with real data MailMerge needs even 4
seconds.
And now here the source code with a workaround - i simply reload the document using a memory stream before i do MailMerge:
log.Debug("Bookmark Count = " +
doc.Range.Bookmarks.Count);
int i = 0;
foreach (Aspose.Word.Bookmark bookmark in
doc.Range.Bookmarks)
{
if ((i / 10) % 2 == 0)
{
bookmark.Text
= string.Empty;
}
i++;
}
log.Debug(“Bookmarks processed”);
using (MemoryStream ms = new MemoryStream())
{
doc.Save(ms,SaveFormat.FormatDocument);
ms.Position = 0;
doc = new Document(ms);
}
log.Debug(“MailMerge Start”);
doc.MailMerge.Execute(new string[] {}, new object[]
{});
log.Debug(“MailMerge Stop”);
Here os the output:
2005-11-24 15:36:36,361 [2396] DEBUG Tests.Class1 - Bookmark Count = 486
2005-11-24 15:36:36,691 [2396] DEBUG Tests.Class1 - Bookmarks processed
2005-11-24 15:36:37,192 [2396] DEBUG Tests.Class1 - MailMerge Start
2005-11-24 15:36:37,232 [2396] DEBUG Tests.Class1 - MailMerge Stop
Now you see the MailMerge ist much faster.
I hope this helps.
Cheers
Robert