From 30e4515287e72a74987bae33ece4b75f49bf6db3 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 21 Nov 2019 20:20:56 +0000 Subject: [PATCH] improve DataTable passing to Export --- Export-Excel.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index de3f59d..76f6766 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -575,7 +575,7 @@ $existingTable = $ws.Tables.Where({$_.address.address -eq $ws.dimension.address},'First', 1) if ($null -eq $TableName -and $existingTable) { $TableName = $existingTable.Name - $TableStyle = $existingTable.Tablestyle + $TableStyle = $existingTable.StyleName -replace "^TableStyle","" $AutoFilter = $false } #if we did not get $autofilter but a filter range is set and it covers the right area, set autofilter to true @@ -623,10 +623,10 @@ if it is a data table don't do foreach on it (slow) - put the whole table in and set dates on date columns, set things up for the end block, and skip the process block #> if ($InputObject -is [System.Data.DataTable]) { - if ($Append) { + if ($Append -and $ws.dimension) { $row ++ $null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, $false ) - if ($TableName) { + if ($TableName -or $PSBoundParameters.ContainsKey('TableStyle')) { Add-ExcelTable -Range $ws.Cells[$ws.Dimension] -TableName $TableName -TableStyle $TableStyle } }