title: Open XML: How to add rows and cell value after appending new sheet in existing Excel file using c#
body: <p>I inserted/appended new sheet in existing Excel file using open XML but I am not able to add rows and cell values. Following is my code: </p>
  
  <pre><code>  using (var workbook = SpreadsheetDocument.Open(excelFilePath, true))
              {
                  var workbookPart = workbook.WorkbookPart;
                  var wb = workbookPart.Workbook;
                  int rowIndex = 0;
                  // Add a blank WorksheetPart.
                  WorksheetPart newWorksheetPart = workbook.WorkbookPart.AddNewPart&lt;WorksheetPart&gt;();
                  newWorksheetPart.Worksheet = new Worksheet(new SheetData());
                  Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;();
                  string relationshipId = workbook.WorkbookPart.GetIdOfPart(newWorksheetPart);
  
                  // Get a unique ID for the new worksheet.
                  uint sheetId = 1;
                  if (sheets.Elements&lt;Sheet&gt;().Count() &gt; 0)
                  {
                      sheetId = sheets.Elements&lt;Sheet&gt;().Select(s =&gt; s.SheetId.Value).Max() + 1;
                  }
  
                  // Give the new worksheet a name.
                  string sheetName = "Data";
  
                  // Append the new worksheet and associate it with the workbook.
                  Sheet dataSheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
                  sheets.Append(sheet);
                  workbookPart.Workbook.Save();
                  var sharedStringPart = workbookPart.SharedStringTablePart;
                  var values = sharedStringPart.SharedStringTable.Elements&lt;SharedStringItem&gt;().ToArray();
                  Row headerRow = new Row();
                  Cell cell = new Cell();
                  cell.DataType = CellValues.String;
                  cell.CellValue = new CellValue("EmpId");
                  headerRow.AppendChild&lt;Cell&gt;(cell);
                  cell = new Cell();
                  cell.DataType = CellValues.String;
                  cell.CellValue = new CellValue("Name");
                  headerRow.AppendChild&lt;Cell&gt;(cell);
  
                  headerRow.AppendChild&lt;Cell&gt;(cell);
                  dataSheet.InsertAt&lt;Row&gt;(headerRow, rowIndex++);
                  workbookPart.Workbook.Save();
              }
          }
  </code></pre>
  
  <p>It's throwing an exception:</p>
  
  <blockquote>
    <p>Non-composite elements do not have child elements.</p>
  </blockquote>