How to access this object in Powershell?

Feb 8, 2013 at 6:00 PM

I'm trying to use this library in Powershell on Windows 7/Server2008R2.
Do you have any examples of using it? If so how do I create a object from it?

Also, I had to change the targetFramework to .net 3.5 so it would load in Powershell.

$a = New-Object [Excel.ExcelBinaryReader]


PS C:\Windows\system32> $filepath="C:\Users\me\Downloads\2.1.beta.src\Excel\bin\Debug\Excel.4.0.dll"


$a = New-Object [Excel.ExcelBinaryReader]

New-Object -TypeName [Excel.4.0].IExcelDataReader


GAC Version Location

False v2.0.50727 C:\Users\me\Downloads\2.1.beta.src\Excel\bin\Debug\Excel.4.0.dll
New-Object : Cannot find type [[Excel.ExcelBinaryReader]]: make sure the assembly containing this type is loaded.
At line:5 char:16
  • $a = New-Object <<<< [Excel.ExcelBinaryReader]
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Feb 9, 2013 at 1:36 AM
The constructor for ExcelBinaryReader is internal. There's code for how to use the project on the project home page. Load the assembly as you did, then get a FileStream:
> $file = [System.IO.File]::OpenRead("$($pwd.Path)\Book1.xls")
Pass the FileStream to the factory method:
> $reader = [Excel.ExcelReaderFactory]::CreateBinaryReader($file)
And read from it as directed on the home page. You should make sure to close and dispose the reader and file when you're done with them.