首页 > 解决方案 > 无法通过 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();

标签: c#apidocumentationdelete-row

解决方案


您应确保tableStartLocation请求中的值与startIndex您正在编辑的文档中尝试访问的表的值相匹配。

文档 JSON 的相应部分startIndex应如下所示:

      {
        "startIndex": 12,
        "endIndex": 23,
        "table": {...}
      },

在此处查看谷歌跟踪器中的相关问题:https ://issuetracker.google.com/issues/158124540


推荐阅读