3
votes

I am trying to read Excel file using PowerShell. My script works on my machine but it generates the following error when I run it on the server where MS Office is not installed. The client will not intall MS Office on the server. How can I solve this problem?

Error:

Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

Script:

$objExcel = New-Object -ComObject "Excel.Application"

I have tried to load Microsoft.Office.Interop.Excel.dll in my script by coping it to the server. But it doesn't help.

I have tried this solution this solution, but it generates microsoft.jet.oledb.4.0 provider is not registered on the local machine

2
You should probably export your files in CSV format and then call Import-CSV from Powershell to read the data. And yes, "just" copying the DLL won't do, you need at least partial install of MS Office that includes MS Excel to make calls for New-Object -ComObject "Excel.Application" work.Vesper
You can't create an instance of Excel.Application without Excel being installed. (Excel is the Excel.Application you're trying to create an instance of, and clearly you can't do so if it doesn't exist.)Ken White
unzip the excel file, and use XML?SeanC
do yoy mean, first save it as zip and then unzip it and open sheet1.xml, because it is so big that VS cannot open it.user217648

2 Answers

3
votes

Try EPPlus libary. It's a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).

There at least three PowerShell modules available, that use that library:

0
votes

FYI, I solved this problem using OfficeOpenXml.ExcelPackage.