This Content is from Stack Overflow. Question asked by SavedByJESUS
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:usersadministratormy_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.
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
This Question was asked in StackOverflow by SavedByJESUS and Answered by SavedByJESUS It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.