ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

HasErrors is still present on the excel output even it is excluded in property.

Open blhf opened this issue 7 years ago • 5 comments

PowerShell Info: Name Value


PSVersion 5.1.14393. PSEdition Desktop PSCompatibleVersions {1.0, 2.0, BuildVersion 10.0.14393 CLRVersion 4.0.30319. WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

I'm still getting the HasErrors field in excel.

Here is my PowerShell script: Invoke-Sqlcmd -Query "select @@version" -Database master -ServerInstance localhost | Select-Object -Property * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors | Export-Excel "D:\OutputFile.xlsx"

See screenshot of issue:

image

blhf avatar Jul 23 '19 08:07 blhf

Export-Excel now supports DataTables, try this.

$DataTable = Invoke-Sqlcmd -Query "select @@Version" -Database master -ServerInstance localhost -OutputAs DataTables
Export-Excel "D:\OutputFile.xlsx" -InputObject $DataTable

ili101 avatar Jul 23 '19 18:07 ili101

That looks like you have run the same script more than once against the same file, and over written first column E, then D, then C, then B
Either delete the file before exporting or use -ClearSheet

if you remove the export is the right data coming out of the select.

@ili101 has also pointed out there is a better way when you have a datatable.

jhoneill avatar Jul 23 '19 18:07 jhoneill

That looks like you have run the same script more than once against the same file, and over written first column E, then D, then C, then B Either delete the file before exporting or use -ClearSheet

if you remove the export is the right data coming out of the select.

@ili101 has also pointed out there is a better way when you have a datatable.

Hope you can share your script using the -ClearSheet. Thank you.

blhf avatar Jul 24 '19 07:07 blhf

Export-Excel now supports DataTables, try this.

$DataTable = Invoke-Sqlcmd -Query "select @@Version" -Database master -ServerInstance localhost -OutputAs DataTables
Export-Excel "D:\OutputFile.xlsx" -InputObject $DataTable

Exactly what I need. Thanks Mate!

blhf avatar Jul 24 '19 07:07 blhf

Export-Excel "D:\OutputFile.xlsx" -clearsheet or better Export-Excel "D:\OutputFile.xlsx" -WorksheetName "Name" -ClearSheet

jhoneill avatar Jul 24 '19 09:07 jhoneill