ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

Formatting weirdness when adding rows to a table

Open sba923 opened this issue 9 months ago • 14 comments

Start with an Excel table that looks like this:

Image

If you try to add two more rows to the table using

$newrows = @(
    [PSCustomObject]@{
        A=10
        B=11
        C=12
    },
    [PSCustomObject]@{
        A=20
        B=21
        C=22
    }
)
$newrows | Export-Excel -Path (Join-Path -Path $PSScriptRoot -ChildPath 'modified2.xlsx') -WorksheetName 'Sheet1' -Table 'Table1' -Append

You'll get a new formatting for the extended table:

Image

Removing the -Table 'Table1' parameter preserves the formatting:

Image

Code, input file and output files in:

AddRowsToTable.zip

sba923 avatar Jan 20 '25 22:01 sba923