Export-Excel fails on Add-Worksheet
Add-Worksheet : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\7.1.1\Public\Export-Excel.ps1:129 char:26
-
$ws = $pkg | Add-Worksheet @params
I noticed that the @params is used instead of the $params... any reasons why? I'm not very familiar with PS, but it fails right there...
This is my source line: $excel = $data|Export-Excel -Path $OutputFilePath2 -PassThru -TableStyle Medium3 -TableName "data" -WorksheetName "data_partners"
$data is a System.Array of objects with the same 4 properties.
PS C:\WINDOWS\system32> $PSVersionTable.PSVersion
Major Minor Build Revision
5 1 17763 1007
Please post the data used in the array, or create a simple repro and post that.
How about the sample?
`$data = ConvertFrom-Csv @" Region,Date,Fruit,Sold North,1/1/2017,Pears,50 South,1/1/2017,Pears,150 East,4/1/2017,Grapes,100 West,7/1/2017,Bananas,150 South,10/1/2017,Apples,200 North,1/1/2018,Pears,100 East,4/1/2018,Grapes,200 West,7/1/2018,Bananas,300 South,10/1/2018,Apples,400 "@ | Select-Object -Property Region, @{n = "Date"; e = {[datetime]::ParseExact($_.Date, "M/d/yyyy", (Get-Culture))}}, Fruit, Sold
$xlfile = "$env:temp\multiplePivotTables.xlsx" Remove-Item $xlfile -ErrorAction SilentlyContinue
$excel = $data | Export-Excel $xlfile -PassThru -AutoSize -TableName FruitData`
Fails at the same place
Here is something else: `$xlSourcefile = "C:\Temp\Transactions_report\data.xlsx"
$excel = Open-ExcelPackage $xlSourcefile
Add-Worksheet -ExcelPackage $excel -WorkSheetname "NewSheet"`
Add-Worksheet : Cannot process argument transformation on parameter 'ExcelPackage'. Cannot convert the "OfficeOpenXml.ExcelPackage" value of type "OfficeOpenXml.ExcelPackage" to type "OfficeOpenXml.ExcelPackage". At line:1 char:29
- Add-Worksheet -ExcelPackage $excel -WorkSheetname "NewSheet"
-
~~~~~~- CategoryInfo : InvalidData: (:) [Add-Worksheet], ParameterBindingArgumentTransformationException
- FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-Worksheet
I'm using the latest version: PS C:\WINDOWS\system32> gmo -list importexcel
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
Script 7.1.1 ImportExcel {Add-ConditionalFormatting, Add-ExcelChart, Add-ExcelDataValidationRule, Add-ExcelName...}
Ok, found the problem.
I had loaded PSExcel, then installed importExcel, but it was using an old version of EPPlus, hence the problem.
Restarted the ISE, commented the PSEXcel, and now it runs fine.