我使用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
值匹配。
与startIndex
对应的文档JSON的对应部分应如下所示:
{
"startIndex": 12,
"endIndex": 23,
"table": {...}
},
在此处查看Google跟踪器中的相关问题:https://issuetracker.google.com/issues/158124540