在Google电子表格中插入一行:无法写入空行;请改用delete

时间:2015-09-15 13:06:18

标签: java google-api google-spreadsheet-api

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

@FindAll( {@FindBy(xpath = "//div[@id=':2'] //td[@tabindex='-1'] //span[2]")} )
private List<WebElement> allMessagesPerPage;

例外:

$scope.ngmodelfield = {};
$scope.categories = [{
  cat: "Cat 1a",
  translationTag: "OccupationalSafety"
}, {
  cat: "Cat 1b",
  translationTag: "IndustrialSafety"
}, {
  cat: "Cat 2",
  translationTag: "Growth"
}, {
  cat: "Cat 3",
  translationTag: "Modifications"
}, {
  cat: "Cat 4",
  translationTag: "Maintenance"
}, {
  cat: "Cat 5",
  translationTag: "Renewals"
}, {
  cat: "Cat 6",
  translationTag: "Environment"
}, {
  cat: "Cat 7",
  translationTag: "IT"
}, {
  cat: "Cat 8",
  translationTag: "ResearchAndDevelopment"
}, {
  cat: "Cat 9",
  translationTag: "LegalRequirements"
}];

完整的故事简短:上面的示例与我需要修复的应用程序中的代码非常相似,并且应用程序很久以前就已经运行了。 我设法通过了OAuth2身份验证。

1 个答案:

答案 0 :(得分:3)

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

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

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

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