title: How to insert before row in the OpenXml SDK SpreadsheetDocument Table?
body: <p>This my insert after row code:</p>
  
  <pre><code>using (var spreadSheet = SpreadsheetDocument.Open(memoryStream, true, openSettings))
  {
  
      var worksheet = GetWorksheet(spreadSheet);
      var worksheetPart = worksheet.WorksheetPart; 
      var sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();
  
      var newRowIndex = 9;
      foreach (var item in Items)
      {
          newRowIndex++;
  
          var newRow = new Row()
          {
              RowIndex = (uint)newRowIndex
          };
          var lastRow = sheetData.Elements&lt;Row&gt;().LastOrDefault(l =&gt; l.RowIndex == newRowIndex - 1); 
  
          sheetData.InsertAfter(newRow, lastRow);
      }
  
      worksheet.Save(); 
  
  }
  </code></pre>
  
  <p>And my excel report template:</p>
  
  <p><img src="https://i.stack.imgur.com/6mzAe.png" alt="enter image description here"></p>
  
  <p>This code works fine, but result is not correct. The problem is that new rows should insert before 9<sup>th</sup> row. </p>
  
  <p>How can I solve this problem?</p>