gpt4 book ai didi

java - 在 Google 电子表格 : Blank rows cannot be written; use delete instead 中插入一行

转载 作者:搜寻专家 更新时间:2023-11-01 03:02:23 25 4
gpt4 key购买 nike

我无法向现有电子表格添加行。我正在尝试从这里开始的步骤:https://developers.google.com/google-apps/spreadsheets/data以下行抛出以下异常:

row = service.insert(listFeedUrl, row);

异常(exception):

Exception in thread "main" com.google.gdata.util.InvalidEntryException: Bad Request
Blank rows cannot be written; use delete instead.

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:602)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.insert(Service.java:1409)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:613)
at TestGoogle.main(TestGoogle.java:93)

完整的故事简介:上面的示例与我需要修复的应用程序中的代码非常相似,并且该应用程序在一段时间之前就可以运行。我成功通过了OAuth2认证。

最佳答案

您收到此错误消息的原因可能是因为您正在尝试添加到空白电子表格,而标题不存在。

如果我们先添加 header ,那么它应该可以工作。

使用您链接的文档中的“添加列表行”示例;在添加列表行之前添加这样的标题

CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
CellFeed cellFeed = service.Query(cellQuery);

CellEntry cellEntry = new CellEntry(1, 1, "firstname");
cellFeed.Insert(cellEntry);
cellEntry = new CellEntry(1, 2, "lastname");
cellFeed.Insert(cellEntry);
cellEntry = new CellEntry(1, 3, "age");
cellFeed.Insert(cellEntry);
cellEntry = new CellEntry(1, 4, "height");
cellFeed.Insert(cellEntry);

然后列表条目示例应该正确地添加到电子表格

// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "firstname", Value = "Joe" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "lastname", Value = "Smith" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "age", Value = "26" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "height", Value = "176" });

// Send the new row to the API for insertion.
service.Insert(listFeed, row);

关于java - 在 Google 电子表格 : Blank rows cannot be written; use delete instead 中插入一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32586913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com