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.

1
  • 4
    How about using the great module from Doug Finke ImportExcel? Commented Sep 18, 2022 at 15:58

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Glad it worked for you
@DougFinke It sure did! Thank you for an awesome, easy-to-use module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.