【发布时间】:2014-02-28 07:42:40
【问题描述】:
在我想关闭文件然后关闭 word 应用程序之后,我正在执行邮件合并。这是我执行邮件合并的地方
Application myWordApp = new Application();
Word.Document myWordDoc = new Word.Document();
myWordDoc = myWordApp.Documents.Add(ref fileDocTempl, ref oMissing, ref oTrue);
myWordApp.Visible = false;
Word.MailMerge wrdMailMerge = myWordDoc.MailMerge;
List<object> listTable = GetTableName();
const string cmdText = "Select * from [{0}]";
Object oQuery = string.Format(cmdText, listTable[0]);
wrdMailMerge.OpenDataSource(excelSource, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,oMissing, oMissing, oMissing, oMissing, oMissing, oQuery);
myWordApp.MailMergeAfterRecordMerge += myWordApp_MailMergeAfterRecordMerge;
myWordDoc.MailMerge.Execute(ref oFalse);
这是我关闭文件的地方
object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
myWordDoc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
myWordApp.Quit(ref doNotSaveChanges, ref oMissing, ref oMissing);
但是当我关闭 myWordDoc 时出现以下错误:
RPC_E_CALL_REJECTED COMexeption
只有在我进行大量邮件合并时才会发生这种情况,如果我尝试使用 50 一切正常,如果我尝试使用 2000 我会收到报告的错误。
【问题讨论】:
-
将您的 2000 个列表拆分为 50 个记录的列表?
-
我需要表演,而 2000 年只是程序要做的一小部分,它会合并 40 000 封邮件甚至更多,我认为拆分可能会降低表演
-
这可能有点晚了,但是如果您可以使用 OpenXML 库而不是互操作,尤其是如果您希望它在无人值守的情况下运行。
-
已解决:我刚刚杀死了进程!
标签: c# exception ms-word interop mailmerge