title: Entering a string with new line characters into excel using powershell
body: <p>I have a string str.</p>
  
  <pre><code>$str="abcd_1
        abcd_2
        abcd_3"
  </code></pre>
  
  <p>First in the for-loop I am concatenating the string and making a full string of Id's with a carriage return+newline character.
  And on splitting I am using just the new line character.
  I am getting a space in front in the data which is entered from the second cell.</p>
  
  <pre><code>for($intRow = $trow ; $intRow -le $maxRow ; $intRow++){
  
                              $codeName = $currentCode
                              $fin = $codeName + "_" + $i + "`r`n"
                              $finCode=$finCode+$fin
  
  
                              $i= $i + 1
                           }
  
  
  
                           $currentSheet.Cells.Item($fRow,$currentCol).Value2  = $finCode
  
  
  
                           $clipboardData = $finCode.Split("`n").TrimStart()
                           $newClipboardData = $clipboardData.Where({$_.TrimStart() -ne ""}).ForEach({$_.TrimStart()})
                           [System.Windows.Forms.Clipboard]::SetText($newClipboardData)
  
  
  
                           $currentSheet.Cells.Item($fRow,$currentCol).Select() | Out-Null
                           $currentSheet.Paste() | Out-Null
  </code></pre>