Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Excel files where Office is not installed using PowerShell

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

like image 421
user217648 Avatar asked Sep 02 '25 07:09

user217648


2 Answers

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:

  • PSExcel. More info: PSExcel: Excel automation without Excel
  • ExcelPSLib
  • ImportExcel
like image 114
beatcracker Avatar answered Sep 05 '25 00:09

beatcracker


FYI, I solved this problem using OfficeOpenXml.ExcelPackage.

like image 33
user217648 Avatar answered Sep 05 '25 01:09

user217648