0

As many of you are aware, PowerShell can now be installed and used on Linux and it has worked surprisingly well for me so far. However, I wonder if the content of an Excel file can be read given that Excel cannot be installed on Linux. What I have found online is that the PS script to open an Excel file is:

# Script copied and pasted from https://stackoverflow.com/questions/48443536/how-to-read-excel-files-in-powershell

$excel = New-Object -com excel.application
$wb = $excel.workbooks.open("c:\users\administrator\my_test.xls")

But I get the error:

New-Object: A parameter cannot be found that matches parameter name 'com'.

When I remove the parameter and run the script, this is the error I get:

New-Object: Cannot find type [excel.application]: verify that the assembly containing this type is loaded.

Since I'm on Linux (ubuntu 22.04), I can use xls2csv on bash to convert the Excel file to csv and then use Get-Content on PowerShell. But I would like to know if there is a way to do it on PowerShell since I am currently learning it.

Thank you.

SavedByJESUS
  • 3,262
  • 4
  • 32
  • 47
  • 4
    How about using the great module from Doug Finke [ImportExcel](https://www.powershellgallery.com/packages/ImportExcel)? – Olaf Sep 18 '22 at 15:58

1 Answers1

3

I am grateful to @Olaf who pointed out the ImportExcel module from Doug Finke.

After installing the module with:

Install-Module -Name ImportExcel

importing the file is as easy as:

$data = Import-Excel c:\users\administrator\my_test.xls
SavedByJESUS
  • 3,262
  • 4
  • 32
  • 47