Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Smartsheet SDK(2.0)API-清除单元格_C#_Smartsheet Api_Smartsheet C# Sdk V2 - Fatal编程技术网

C# Smartsheet SDK(2.0)API-清除单元格

C# Smartsheet SDK(2.0)API-清除单元格,c#,smartsheet-api,smartsheet-c#-sdk-v2,C#,Smartsheet Api,Smartsheet C# Sdk V2,在一天中的某个时刻,我需要通过C#SDK(Nuget软件包)将智能表上的数据重置为空 下面是一个原型代码片段 // Connect tp Smartsheet API SmartsheetClient ss = new SmartsheetBuilder().SetAccessToken(myAccessToken).Build(); // Load in the Sheet Sheet sheet = ss.SheetResources.GetSheet(mySheetID, null, n

在一天中的某个时刻,我需要通过C#SDK(Nuget软件包)将智能表上的数据重置为空

下面是一个原型代码片段

// 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() });
所以,底线问题是。。。如何删除单元格值?

快速回答:

只需将空字符串设置为单元格值<代码>更新CellBuilder(dataCell.ColumnId,String.Empty)

讨论:

Smartsheet无法区分不同类型的空单元格。因此,发送null和空字符串在逻辑上没有区别


底层REST/JSON API对缺少的元素和显式null有不同的表示。用C#这样的强类型语言来表示这两种情况更加困难。(我愿意接受建议。)

作为对讨论点的回答,您可以简单地添加一个
ClearCell(dataCell.ColumnId)
方法
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