2017-07-12 46 views
0

在某一點,我需要通過C#SDK重置上的Smartsheet的數據(到NULL)(NuGet包)Smartsheet SDK(2.0)API - 白天清除細胞

這裏的一個原型代碼代碼段

// Connect tp Smartsheet API 
SmartsheetClient ss = new SmartsheetBuilder().SetAccessToken(myAccessToken).Build(); 

// Load in the Sheet 
Sheet sheet = ss.SheetResources.GetSheet(mySheetID, null, null, null, null, null, null, null); 

// Get the row/cell we want to update 
Row dataRow = sheet.Rows[0]; 
Cell dataCell = dataRow.Cells[9]; 
UpdateRowBuilder rb = new Row.UpdateRowBuilder(dataRow.Id); 

// 
// SET THE VALUE OF THE CELL HERE 
// 
List<Cell> resetCells = new List<Cell>(); 
resetCells.Add(new Cell.UpdateCellBuilder(dataCell.ColumnId, null).Build()); 

// Save the Sheet 
ss.SheetResources.RowResources.UpdateRows(mySheetID, new List<Row>() { rb.SetCells(resetCells).Build() }); 

如果我的單元格的值設置爲一個(字符串)的值,則所有是非常愉快和片材保存,並且該值出現

但是,如果我的值設置爲NULL然後我得到一個例外...

Smartsheet.Api.InvalidRequestException: Required object attribute(s) are missing from your request: cell.value. 
    at Smartsheet.Api.Internal.AbstractResources.HandleError(HttpResponse response) 
    at Smartsheet.Api.Internal.AbstractResources.PutAndReceiveList[T,S](String path, T objectToPut, Type objectClassToReceive) 
    at Smartsheet.Api.Internal.SheetRowResourcesImpl.UpdateRows(Int64 sheetId, IEnumerable`1 rows) 
    at LHRMayfly.LHRMayFly_Processor.Reset() in C:\Projects\SmartSheetProcessor.cs:line 173 

所以,底線的問題是...你如何刪除單元格值?

回答

1

快速回答:

只需設置一個空字符串作爲單元格的值。 UpdateCellBuilder(dataCell.ColumnId, String.Empty)

討論:

Smartsheet不不同種空單元之間進行區分。所以發送空字符串和空字符串沒有邏輯上的區別。

底層的REST/JSON API對缺少的元素和顯式的null有不同的表示形式。用C#這樣的強類型語言來表示這兩種情況更加困難。 (我願意接受建議。)

+0

在回答討論時,您可以簡單地添加一個ClearCell(dataCell.ColumnId)方法 –

+0

...並感謝您的答案......按預期工作 –