pmfith
pmfith

Reputation: 909

Smartsheet C# API add row array below first row

I'm writing C# code to import data into Smartsheet. I'd like to leave a dummy row as the first row, and add all subsequent rows below that. I cannot find a syntax in the documentation to do this. The AddRows method doesn't seem to have any way to determine this. Here is my code:

Cell[] cellsA = new Cell[] 
{ 
new Cell.AddCellBuilder(sheet.Columns[1].Id, taskData[i][1]).Build()                        //summary
,new Cell.AddCellBuilder(sheet.Columns[2].Id, taskData[i][2]).SetStrict(false).Build()         //StartDate
,new Cell.AddCellBuilder(sheet.Columns[3].Id, taskData[i][3]).SetStrict(false).Build()           //DueDate
,new Cell.AddCellBuilder(sheet.Columns[5].Id, taskData[i][4]).Build()                        //Estimated Hrs.
,new Cell.AddCellBuilder(sheet.Columns[6].Id, taskData[i][5]).Build()                        //Completion
,new Cell.AddCellBuilder(sheet.Columns[7].Id, taskData[i][6]).Build()                        //OWner
,new Cell.AddCellBuilder(sheet.Columns[8].Id, taskData[i][7]).Build()                        //Priority
,new Cell.AddCellBuilder(sheet.Columns[9].Id, taskData[i][8]).Build()                        //Status
,new Cell.AddCellBuilder(sheet.Columns[10].Id, taskData[i][9]).Build()                        //Category
,new Cell.AddCellBuilder(sheet.Columns[11].Id, screenURL + taskData[i][0]).Build()           
};

// Specify contents of first row.
Row rowA = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsA).Build();

// Add rows to sheet.
smartsheet.SheetResources.RowResources.AddRows(SheetID, new Row[] { rowA });

Upvotes: 0

Views: 531

Answers (2)

pmfith
pmfith

Reputation: 909

The key to adding a row below the first row lies in the line of code to create the new row - specifically, the second parameter determining the ?bool 'toBottom' property. Example:

 // Specify contents of first row.
 Row rowA = new Row.AddRowBuilder(null, true, null, null, null).SetCells(cellsA).Build();

Upvotes: 1

daveskull81
daveskull81

Reputation: 637

I would suggest adding the dummy row to your sheet first. In the response you'll be given the new rows Id that you can store for later use. Then as you add new rows to the sheet you can set the siblingId for the new rows to that row Id and they will come in directly under that row.

Another approach would be to add the dummy row first and then as you add new rows set the location using toBottom to place the rows at the bottom of the sheet each time. More info on row location can be found in the docs here: http://smartsheet-platform.github.io/api-docs/?csharp#row-location

Upvotes: 0

Related Questions