Smartsheet.Api.Internal.SheetRowResourcesImpl.AddRows C# (CSharp) Method

AddRows() public method

Inserts one or more rows into the Sheet specified in the URL.

It mirrors To the following Smartsheet REST API method: POST /sheets/{sheetId}/rows

If multiple rows are specified in the request, all rows must be inserted at the same location (i.e. the toTop, toBottom, parentId, siblingId, and above attributes must be the same for all rows in the request).
if any argument is null or empty string if there is any problem with the REST API request if there is any problem with the REST API authorization (access token) if the resource cannot be found if the REST API service is not available (possibly due To rate limiting) if there is any other error during the operation
public AddRows ( long sheetId, IEnumerable rows ) : IList
sheetId long the sheet Id
rows IEnumerable one or more rows
return IList
        public virtual IList<Row> AddRows(long sheetId, IEnumerable<Row> rows)
        {
            foreach (Row row in rows)
            {
                row.Id = null;
            }
            return this.PostAndReceiveList<IEnumerable<Row>, Row>("sheets/" + sheetId + "/rows", rows, typeof(Row));
        }

Usage Example

Example #1
0
        public virtual void TestAddRows()
        {
            server.setResponseBody("../../../TestSDK/resources/addRows.json");

            // Create a set of cells
            IList <Cell> cells = new List <Cell>();
            Cell         cell  = new Cell.AddCellBuilder(123, "lala").SetStrict(true).Build();

            cells.Add(cell);

            // Create a row and add the cells to it.
            IList <Row> rows = new List <Row>
            {
                new Row.AddRowBuilder(true, null, null, null, null).SetCells(cells).Build(),
                new Row.AddRowBuilder(null, null, 123, null, null).SetFormat("A").Build()
            };

            IList <Row> newRows = sheetRowResource.AddRows(2331373580117892L, rows);

            Assert.NotNull(newRows);
            Assert.AreEqual(2, newRows.Count, "The number of rows created & inserted is not correct.");
            Assert.AreEqual(2331373580117892, newRows[1].SheetId);

            Column col = new Column();

            col.Id = 8764071660021636L;
            Assert.Null(rows[0].GetColumnByIndex(0));
            Assert.Null(rows[0].GetColumnById(8764071660021636L));
        }