Java 在谷歌电子表格中插入一行:无法写入空白行;改用delete

Java 在谷歌电子表格中插入一行:无法写入空白行;改用delete,java,google-api,google-spreadsheet-api,Java,Google Api,Google Spreadsheet Api,我无法将行添加到现有电子表格中。 我正在尝试以下步骤: 以下行引发以下异常: row = service.insert(listFeedUrl, row); 例外情况: Exception in thread "main" com.google.gdata.util.InvalidEntryException: Bad Request Blank rows cannot be written; use delete instead. at com.google.gdata.client.ht

我无法将行添加到现有电子表格中。 我正在尝试以下步骤: 以下行引发以下异常:

row = service.insert(listFeedUrl, row);
例外情况:

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身份验证。

您收到此错误消息的原因可能是您试图添加到一个空白的电子表格,但标题不存在

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

使用链接文档中的“添加列表行”示例;在添加列表行之前,添加如下标题

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);

“空行无法写入”是错误,行是否为空。。。新增列表行单据否,该行不为空。我在“添加列表行”部分尝试了上述文档示例中的确切代码。列表提要使用起来有点混乱,我很久以前就切换到了单元格提要。我不记得细节了,但我不得不用它来试验,以了解它允许什么。我知道您需要行标题,但不确定它是否允许空白单元格。