Search code examples
c#asp.netsmartsheet-api

Add row at specific position in smartsheet using Smartsheet-API?


Cell[] cellsA = new Cell[] { new Cell.AddCellBuilder(7960873114331012, true).Build(),
new Cell.AddCellBuilder(642523719853956, "New status").SetStrict(false).Build()
};

Row rowA = new Row.AddRowBuilder(true,null,null,null,null).SetCells(cellsA).Build();

smartsheet.SheetResources.RowResources.AddRows(873476834787, new Row[] { rowA});

I want to add this row at a specific position like after 5th row.

enter image description here


Solution

  • In the Smartsheet C# SDK, AddRowBuilder is defined as follows:

    enter image description here

    When calling AddRowBuilder, you can specify the final two parameters (siblingId and above) to insert the new row directly above an existing row in the sheet. Note that siblingId should specify the GUID for that row -- not the row number that indicates its position in the sheet. For example, if you want to insert the new row directly above the row that has an ID of 7670198317672324, your code would read like this:

    Row rowA = new Row.AddRowBuilder(null,null,null,7670198317672324,true).SetCells(cellsA).Build();