【发布时间】:2015-11-24 06:05:45
【问题描述】:
我正在尝试从 Windows 8.1 通用应用程序创建、打开、读取/写入 .docx 文件。我正在使用 Visual Studio 2013。
当我初始化一个 Interop.Word.Application
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
我收到一个错误
An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code
Additional information: Creating an instance of the COM component with CLSID
{000209FF-0000-0000-C000-000000000046} using CoCreateInstanceFromApp failed due
to the following error: 80040154 Class not registered (Exception from HRESULT:
0x80040154 (REGDB_E_CLASSNOTREG)). Please make sure your COM object is in the
allowed list of CoCreateInstanceFromApp.
我环顾四周,找不到任何与我的问题相符的东西。我已经看到这个权限不足的异常,但我以管理员身份运行,但没有运气。
感谢任何帮助。如果您需要更多信息,请告诉我。
编辑 1
我在创建这个应用程序时确实做了一些奇怪的事情。我无法像过去那样添加对 Microsoft.Office.Interop 的引用,所以我按照我在网上找到的一些说明进行操作,并通过指向添加它们
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Word.dll
我不确定这是否有帮助,但这是我做的唯一一件看起来不正常的事情。
【问题讨论】:
-
Word 真的安装了吗?您是否尝试在 Windows 服务或 IIS 中执行此操作?
-
是的。我可以打开单词、读/写和保存。