c# - 无法通过 Google Docs API 删除表中的行
问题描述
我使用 Google 文档尝试使用 DeleteTableRowRequest 删除表中的某些行,但我遇到了指定 TableStartLocation 属性的异常。我的代码如下:
public static void DeleteRequestGDocs(List<Request> requestsList, int? index2Del)
{
Request request = new Request();
Location tableLocation = new Location();
tableLocation.SegmentId = string.Empty;
tableLocation.Index = 11;
TableCellLocation tableCellLocationDel = new TableCellLocation();
tableCellLocationDel.RowIndex = index2Del;
tableCellLocationDel.ColumnIndex = 0;
tableCellLocationDel.TableStartLocation = tableLocation;
DeleteTableRowRequest delRequest = new DeleteTableRowRequest();
delRequest.TableCellLocation = tableCellLocationDel;
request.DeleteTableRow = delRequest;
requestsList.Add(request);
}
请帮我
更新1:当程序执行删除。我遇到了错误“无效的请求 [0].deleteTableRow:无效的表起始位置。必须指定表的起始索引。” 用下面的代码
var bodyDelete = new BatchUpdateDocumentRequest();
bodyDelete.Requests = requestsDeleteList;
var batchDeleteRequest = docsService.Documents.BatchUpdate(bodyDelete, mergedFile.Id);
var resultDelete = await batchDeleteRequest.ExecuteAsync();
解决方案
您应确保tableStartLocation
请求中的值与startIndex
您正在编辑的文档中尝试访问的表的值相匹配。
文档 JSON 的相应部分startIndex
应如下所示:
{
"startIndex": 12,
"endIndex": 23,
"table": {...}
},
在此处查看谷歌跟踪器中的相关问题:https ://issuetracker.google.com/issues/158124540
推荐阅读
- tensorflow - 如何将特征列名称添加到 Keras Estimator
- wordpress - 设置 Wordpress 帖子的默认模式
- sas - 如何使用通过在宏中使用 SYSPBUFF 传递的变量列表来屏蔽“或”
- vb.net - 复选框状态保存在文本文件 vb.net
- javascript - 如何打印词典词典的内容?
- groovy - 如何绕过 spock Data provider is null 错误
- c - 头文件的多重包含错误 - C
- android - 我们可以将 Android 屏幕与 React Native 集成吗?
- java - java Socket未连接:连接
- java - 使用改造的 Json 获取请求不起作用