title: Powershell Excel Add row from array
body: <p>I am aware of how to update an Excel speadsheet cell-by-cell via a COM object but it's incredibly slow. I have a pscustomobject array of around 600 objects (user details) with 15 properties (string or boolean).</p>
  
  <p>How would I update a row in Excel by passing each array object to it using Value2? Can someone kindly paste a working example of passing an array and updating a whole row? The following code works for the first row (heading) but no further rows are updated.</p>
  
  <pre><code>$obj_fields = $obj | Get-Member | ?{$_.membertype -eq 'noteproperty'}
  $alpha_column = [char]($obj_fields.count + 96)
  
  If ($row -eq 2) {
     #heading
     $range = $SPREADSHEET_WORKSHEET_2.cells.Item(1,1).range("a1`:$($alpha_column)1")
     $range.Value2 = $obj_fields.Name
  }
  #values 
  $range = $SPREADSHEET_WORKSHEET_2.cells.Item($row,1).range("a$row`:$alpha_column$row")
  $tmp = ($obj_fields | %{$obj."$_"})
  $range.Value2 = $tmp
  </code></pre>
  
  <p><a href="https://powertoe.wordpress.com/2010/11/05/how-to-get-data-into-an-excel-spreadsheet-very-quickly-with-powershell-contd/" rel="nofollow">This</a> post looks similar to what I'm trying to do but I'm not using activesheet and can't get it working.</p>
  
  <p>Thanks all</p>