Reading Excel files where Office is not installed using PowerShell

8.7k views Asked by At

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

There are 2 answers

0
user217648 On

FYI, I solved this problem using OfficeOpenXml.ExcelPackage.

5
beatcracker On

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: