我使用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": {...}
},
请在此处查看谷歌跟踪器中的相关问题:https://issuetracker.google.com/issues/158124540