尝试使用API​​ v4在Google工作表中写一行时出错

时间:2017-09-21 18:27:46

标签: java google-sheets-api

我尝试使用java和Google表格API v4向表格写一行。我收到的错误是我无法理解的。任何帮助将不胜感激!

传递的值是:

  

sRange =' 09/03/2017 11:01:13 PM'!A1
  body = {majorDimension = ROWS,values = [[Test ID,Test Name,Run ID,Status,Run Duration,Execution Date,Execution Time]]}

这是故障代码:

outputValues = Arrays.asList(Arrays.asList("Test ID", "Test Name", "Run ID", "Status", "Run Duration", "Execution Date", "Execution Time"));
sRange = "'" + sSheetName + "'" + "!" + sHeaderRow;
body = new ValueRange().setValues(outputValues).setMajorDimension("ROWS");
result = service.spreadsheets().values().update(sSpreadsheetID, sRange, body).setValueInputOption("RAW").execute();

结果:

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Requested writing within range ['09/03/2017 11:01:13 PM'!A1], but tried writing to column [B]",
    "reason" : "badRequest"
  } ],
  "message" : "Requested writing within range ['09/03/2017 11:01:13 PM'!A1], but tried writing to column [B]",
  "status" : "INVALID_ARGUMENT"
}

2 个答案:

答案 0 :(得分:1)

由于工作表标题中的字符问题,解决了此错误。删除工作表标题中的空格,破折号和冒号,并用下划线替换,以解决问题。

答案 1 :(得分:0)

我认为sRange应该使用A1 notation

看起来像:

SheetName!A1:B2
Sheet1!A1

查看链接以获取更多信息。