'export-excel over-writing rows, and columns winding up out of order

I'm writing to a spreadsheet using Export-Excel, and it's over-writing and re-ordering the rows. I'm following this example: ImportExcel. When the program ends, I see that the row in the spreadsheet is the last row of data obtained. Help would be appreciated...

          $resultHelp = [System.Collections.Generic.List[psobject]]::new() 
          Write-Host "another:"
          $err = $errCode #get each error code to lookup in mdb file
          Write-Host $err
          $resultHelp = ProcessHelpMDB -mdbLookupError $errCode -mdbFilePath $basePathFull -mdbDeviceSeries $Ver #######

          #loop thru results from Help MDB file for $errCode
          foreach($row in $resultHelp.GetEnumerator()) #this is working for each row
          {
              if($row -ne $True) #not sure why it adds true at the top
              {
                Write-Host $row.TextID #prints HELP_JAM; this is key for kapptext.mdb

                #lookup value from kapptext.mdb
                Write-Host $($row.TextID) #prints nothing but looks ok in next function
                $longText = ProcessK_MDB -mdbLookupstring $($row.TextID) #gives English-US from db for parameter given, which is long error instruction
                #export data found above to excel. 
                #### minimal example shows how get each row data since it's part of issue
                #get the data ready to put in spreadsheet
                $result = New-Object psobject -Property @{
                    ScreenNumber = $($row.ScreenNumber)
                    KKey = $($row.TextID)
                    EnglishUS = $($longText)
                    PictureID = $($row.PictureID)
                    ImageFound = ""
                    ImageFileName = ""
                } ##left off...need to get ImageFileName in above data structure next and insert into spreadsheet

                $date = (Get-Date).tostring("MM-dd-yyyy") 
                [System.String] $help_spreadsheet_File = "COMPONENT MAP HELP_",$($date),".xlsx"
                $out_path = '\\company.net\EndToEnd\ComponentMaps'
                $outFilePath = Join-Path -Path $out_path -ChildPath $help_spreadsheet_File
                #write to dated file at out_path location
                #export content to spreadsheet
                $xlsx = $result | Export-Excel -Path $outFilePath -WorksheetName $errCode -Autosize -AutoFilter -FreezeTopRow -BoldTopRow  -PassThru # -ClearSheet can't ClearSheet every time or it clears previous data  ###seems to have issue over-writing each row below header
                $ws = $xlsx.Workbook.Worksheets[$errCode]
                $ws.Dimension.Columns  #number of columns
                $ws.Dimension.Rows     #number of rows
                $ws.Row(1).Height
                $ws.Row(1).Height = 25
                $ws.Column(5).Width
                $ws.Column(5).Width = 50
                Close-ExcelPackage $xlsx

              } #if not true
          } #foreach row $resultHelp

          Write-Host "Break when done with first errCode $($errCode)" #50-9
          Break ##################################

Note that $resultHelp looks like this:

[0] $true (I'm not sure why it puts true at the top)
[1] @(HelpCode=9;ScreenNumber=1;TextID=HELP_...JA;PictureID=HELP_...RIB)
[2] @(HelpCode=9;ScreenNumber=2;TextID=HELP_...ROLL;PictureID=HELP_...ROLL)
[3] @(HelpCode=9;ScreenNumber=3;TextID=HELP_...EDGE;PictureID=HELP_...UT)
...

When it finishes running, spreadsheet contents look like this (headers out of order, only showing last row found in data):

ImageFound   ScreenNumber   ImageFileName   KKEY         EnglishUS            PictureID
             3                              HELP..EDGE   If error persists... HELP_..UT

My question is, how do I keep my column order like the properties list, and also not have it over-write each row added? I haven't found any good examples online where they aren't just reading the data from a csv file in bulk and sending it to spreadsheet in a whole chunk. I'm using PowerShell 5.1 and VSCode.

Update: This fixed the problem with only the last row showing in the spreadsheet per @Santiago:

       foreach ($errCode in $ErrCodes) 
       {
          $resultHelp = [System.Collections.Generic.List[psobject]]::new() 
          Write-Host "another:"
          $err = $errCode #get each error code to lookup in mdb file
          Write-Host $err
          $resultHelp = ProcessHelpMDB -mdbLookupError $errCode -mdbFilePath $basePathFull -mdbDeviceSeries $Ver #######

          #loop thru results from Help MDB file for $errCode
          $result = foreach($row in $resultHelp.GetEnumerator()) #this is working for each row
          {
              if($row -ne $True) #not sure why it adds true at the top
              {
                Write-Host $row.TextID #prints HELP_JAM; this is key for kapptext.mdb
                #lookup value from kapptext.mdb
                Write-Host $($row.TextID) #prints nothing but looks ok in next function
                $longText = ProcessK_MDB -mdbLookupstring $($row.TextID) #gives English-US from db for parameter given, which is long error instruction
                #export data found above to excel. 
                #### minimal example shows how get each row data since it's part of issue
                #get the data ready to put in spreadsheet
                $result = New-Object psobject -Property @{
                    ScreenNumber = $($row.ScreenNumber)
                    KKey = $($row.TextID)
                    EnglishUS = $($longText)
                    PictureID = $($row.PictureID)
                    ImageFound = ""
                    ImageFileName = ""
                } ##left off...need to get ImageFileName in above data structure next and insert into spreadsheet
              } #if not true
          } #foreach row $resultHelp

          $date = (Get-Date).tostring("MM-dd-yyyy") 
          [System.String] $help_spreadsheet_File = "COMPONENT MAP HELP_",$($date),".xlsx"
          $out_path = '\\company.net\EndToEnd\ComponentMaps'
          $outFilePath = Join-Path -Path $out_path -ChildPath $help_spreadsheet_File
           #write to dated file at out_path location
           #export content to spreadsheet
           $xlsx = $result | Export-Excel -Path $outFilePath -WorksheetName $errCode -Autosize -AutoFilter -FreezeTopRow -BoldTopRow  -PassThru # -ClearSheet can't ClearSheet every time or it clears previous data  ###seems to have issue over-writing each row below header
          $ws = $xlsx.Workbook.Worksheets[$errCode]
          $ws.Dimension.Columns  #number of columns
          $ws.Dimension.Rows     #number of rows
          $ws.Row(1).Height
          $ws.Row(1).Height = 25
          $ws.Column(5).Width
          $ws.Column(5).Width = 50
          Close-ExcelPackage $xlsx
          Write-Host "Break when done with first errCode $($errCode)" #50-9
          Break ##################################


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source