我正在尝试使用以下代码从 VB.NET 编辑 word 文档:
如何从 Visual Basic .NET 自动化 Word 以创建新文档
http://support.microsoft.com/kb/316383
它在我的机器上运行良好,但是当我发布到服务器时,出现以下错误。
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.
当我尝试只创建一个单词应用程序对象时会发生实际错误
Dim oWord As New Word.Application
使用 Visual Studio 2008 和 VB.NET 3.5。我引用了“Microsoft Word 10.0 对象库”,并在 bin 目录中看到了 Interop.Word.dll 文件。
在开发机器和 Windows Server 2003 上使用 MS Office 2003
对 .NET 仍然相当陌生,对窗口服务器了解不多,但“UnauthorizedAccessException”听起来像是一个权限问题。我想知道是否有人可以为我指出正确的方向,我可能需要做些什么才能让我的小应用程序访问使用 word。
最佳答案
这绝对听起来像是一个权限问题。您是否在 Windows 服务中运行您的代码?该服务通常作为本地系统运行,它可能没有访问 Word 对象模型的权限。此外,如果 word 已经在使用其他用户的凭据运行,那么您的程序可能无法使用不同的凭据通过 COM 访问它。办公应用程序往往是单一实例,这似乎加剧了这个问题。
关于asp.net - 生成word文档时检索组件错误的COM类工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1190600/