关闭 Word 文档时出错:"The message filter indicated that the application is busy."



我正在使用Microsoft Interop将Word Doc保存为HTML文件,当我尝试关闭文档时,我会遇到此错误:

消息过滤器指示该应用程序很忙。(Hresult的例外:0x8001010a(rpc_e_servercall_retrylater))

这是我的代码:

// word interop setting
object visible = true;
object readOnly = true;
object missing = Type.Missing;
object saveChanges = true;
object htmlFile = (object)Server.MapPath(@"worddoc.html");
object fileType = 
  (object)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML;       
// open document
Microsoft.Office.Interop.Word.Application wordApp =
  new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc =
  wordApp.Documents.Open(ref url, ref missing, ref readOnly, ref missing,
       ref missing, ref missing, ref missing, ref missing, ref missing,
       ref missing, ref  missing, ref  visible, ref missing, ref missing,
       ref missing, ref missing);
try
{                           
    // save the file                 
    wordDoc.SaveAs(ref htmlFile, ref fileType, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing);
}
catch (System.Exception ex)
{
    saveChanges = false;
}
finally
{
    wordDoc.Close(ref saveChanges, ref missing, ref missing); // ERROR HERE
    wordApp.Quit(ref saveChanges, ref missing, ref missing);
    wordDoc = null;
    wordApp = null;
}

有人知道我做错了什么?

您的代码没有任何问题。问题是您正在以不受支持的配置运行它,并且在这种情况下(根据ASP.NET运行)

运行的办公室行为是不确定的

Microsoft当前不建议,也不支持, 来自任何无人看管的Microsoft Office应用程序的自动化, 非相互作用的客户端应用程序或组件(包括ASP, ASP.NET,DCOM和NT服务),因为办公室可能表现出不稳定的 在此环境中运行办公室时的行为和/或僵局。

有关更多信息:

http://support.microsoft.com/kb/257757

您可以使用VSTO服务器文档类使用办公室文档而无需开设办公室。

相关内容

最新更新