在Google电子表格中插入一行:无法写空白行;使用删除代替

乔斯卡

我无法在现有电子表格中添加行。我正在尝试从此处执行的步骤:https : //developers.google.com/google-apps/spreadsheets/data以下行引发以下异常:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用API在新的Google电子表格中创建第一行?

比较Google电子表格上的行

如何使用python GSPREAD查找Google电子表格的第一行?

如何从Google电子表格中删除行?

从最后一行中删除Google电子表格中的重复行

如何通过Python使用SHEET API v4删除Google电子表格中的行?

使用Google表格,将数据从一个电子表格移动到最后一行之后的另一电子表格

如何从电子表格的第一行返回所有值

电子表格中的新行,以使用Google表格中的行ID号添加列

如何在Excel电子表格(与参考表相比)中插入缺少行的空白条目?

在表格中选择下一行时,更新电子表格侧栏中的值

如何使用宏填写电子表格中列表的下一行?

为OOO Calc电子表格中的每一行创建新的txt / html文件

在Google电子表格的一行中搜索两个或多个单词

VBA在很大的电子表格中查找最后一行(溢出错误)

使用Google脚本删除电子表格中的空白行

仅在Google电子表格的最后一行查找和替换

尝试使用Python从Excel电子表格中删除第一行

如何在MS Excel中基于另一电子表格的一行更新电子表格的一行?

如何将电子表格中的两行合并为一行?

如何使用OpenPyXL列出Excel电子表格中的所有第一行值?

我无法在 Google 电子表格中插入值(使用 nodejs 和模块 googleapis)

如何使用谷歌应用程序脚本划掉电子表格的一行(而不是删除它!)?

如何冻结剑道电子表格中的第一行

使用 google-spreadsheet 节点模块向 google 电子表格添加一行并返回状态

根据值或空白隐藏 Google 电子表格中的空白行

谷歌电子表格中每一行的条件格式公式

只有最后一行 Pandas webscraped 数据出现在电子表格中

Google 电子表格转换 GoogleFinance 货币时仅从第一行返回值