RamblingCookieMonster / PSExcel

A simple Excel PowerShell module

Home Page:http://ramblingcookiemonster.github.io/PSExcel-Intro/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export-XLSX - DataView, RowVersion, Row, IsNew, IsEdit columns at the end of all rows

dins2k2 opened this issue · comments

Hello,

When I try to export(sql query resultset) to xlsx from a datatable I see there few additional columns DataView, RowVersion, Row, IsNew, IsEdit are being added at the end of all rows.
Is there any way these columns can be ignored while exporting?

image

Below is the script cut

$dgvReportRsTable= New-Object System.Windows.Forms.DataGridView
$tempSQLDataPath = Join-Path $tempDir "\TempRQD.csv"
$DataSet = New-Object System.Data.DataSet
$nRecs = $SqlAdapter.Fill($DataSet)
$nRecs | Out-Null
$objTable = $DataSet.Tables[0]
$objTable | Export-CSV $tempSQLDataPath
			
$array= new-object System.Collections.ArrayList
$data=@(Import-CSV $tempSQLDataPath)
$array.AddRange($data)
			
$arrayDT = ConvertTo-DataTable -InputObject $array
Load-DataGridView -DataGridView $dgvReportRsTable -Item $arrayDT
			
$dgvReportRsTable.ReadOnly = $true
$dgvReportRsTable.DefaultCellStyle.NullValue = "NULL"
$dgvReportRsTable.AllowUserToAddRows = $false
$dgvReportRsTable.Rows | select -expand DataBoundItem | Export-XLSX -Path $SaveFileDialog.FileName -AutoFit -Force -ClearSheet

Or am I missing anything? Appreciate you help.

Thanks,
Dinesh

Hi Dinesh!

Those are properties native to the object you're looking at. Even if they don't display by default, you can use something like the following to see this:

# View members...
$dgvReportRsTable.Rows | select -expand DataBoundItem | Get-Member

# View data
$dgvReportRsTable.Rows | select -expand DataBoundItem | Select -Property *

Anyhow! To get around this, you can just filter them out, e.g.:

$dgvReportRsTable.Rows |
    Select -ExpandProperty DataBoundItem |
    Select -Property * -ExcludeProperty DataView, RowVersion, Row, IsNew, IsEdit |
    Export-XLSX -Path $SaveFileDialog.FileName -AutoFit -Force -ClearSheet

Cheers!

Thanks Warren for the clarification!
Above code works as expected!

Really appreciate it.