我正在尝试在我的 powershell 脚本中使用 Microsoft.Office.Interop.Excel.dll。我尝试使用的计算机没有安装 Office。 我使用下面的代码添加dll
Add-Type -LiteralPath "D:\Software\microsoft.office.interop.excel\Office.dll"
Add-Type -LiteralPath "D:\Software\microsoft.office.interop.excel\Microsoft.Office.Interop.Excel.dll"
当我尝试使用
创建对象时$excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
我收到的错误为:
New-Object : Exception calling ".ctor" with "0" argument(s): "Retrieving the COM class factory for component with CLSID
{00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154
请推荐。
所有互操作程序集所做的只是在 Office 应用程序本身提供的 COM API 之上提供一个 .NET 友好层。
因此,只有在 Office 也存在的情况下它们才能工作。(相反,PowerShell
可以在没有互操作程序集的情况下与 Office 对话。)