I am trying to use Microsoft.Office.Interop.Excel.dll in my powershell script. The machine on which i am trying to use don't have Office installed. I used below code to add the 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"
when i am trying to create the object using
$excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
I am getting error as:
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
Please suggest.
All the Office PIAs (primary interop assemblies) do is provide a .NET-friendly layer on top of the COM APIs provided by the Office applications themselves.
Therefore, they can only work if Office is present as well.
The error you're getting,
0x80040154, indicates that the underlying Excel COM class isn't registered.(Conversely, it is possible for PowerShell to talk to Office without the interop assemblies, and, when authoring code that needs to run on multiple machines, it may be preferable not to use them, given that their presence cannot be assumed.
New-Object's-Strictswitch issues a warning when the interop assemblies are being used.)As for the ability to work with Office documents without an Office installation present:
ImportExcelmodule.