Java Google 电子表格 API,400 错误错误请求:无法解析范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37893515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:46:01  来源:igfitidea点击:

Google spreadsheet API, 400 error bad request : unable to parse range

javagoogle-sheetsgoogle-api-client

提问by Hemant Yadav

I am trying to access Google spreadsheets using a spreadsheet example. When I run the example code it worked fine. I just change the SpreadsheetIdand range. It started giving me:

我正在尝试使用电子表格示例访问 Google 电子表格。当我运行示例代码时,它运行良好。我只是更改了SpreadsheetId和范围。它开始给我:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Unable to parse range: Class Data!A2:A4",
    "reason" : "badRequest"
  } ],
  "message" : "Unable to parse range: Class Data!A2:A4",
  "status" : "INVALID_ARGUMENT"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.interceptResponse(AbstractGoogleClientRequest.java:321)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
    at poc.mainPOC.main(mainPOC.java:157)

Below is the code:

下面是代码:

  String spreadsheetId = "my spread sheet ID";
    String range = "Class Data!A2:A4";
    ValueRange response = service.spreadsheets().values()
        .get(spreadsheetId, range)
        .execute();

采纳答案by ritesh.garg

Try replacing Class Data!A2:A4with A2:A4

尝试替换Class Data!A2:A4A2:A4

回答by Boom3k

If you look at the sheet itselfyou will notice that the Worksheet is titled "Class Data". So just put the name of your sheet where is says "Class Data". Example: String range = "SheetName!A1:C";

如果您查看工作表本身,您会注意到工作表的标题是“类数据”。因此,只需将工作表的名称放在“类数据”处。示例:String range = "SheetName!A1:C";

回答by slifszyc

I was trying to add some data to a sheet named Emmettthat did not existed yet and was receiving this error:

我试图将一些数据添加到名为的工作表中,该工作表Emmett尚不存在并收到此错误:

Error: Unable to parse range: Emmet!A2:C12

Error: Unable to parse range: Emmet!A2:C12

I had to manually create the sheet named Emmettin the spreadsheet and then it worked like a charm.

我必须手动创建Emmett电子表格中命名的工作表,然后它就像一个魅力。

回答by CodingYourLife

I ran into this error when I had a typo in the name of the tab. In your case "Class Data" didn't match the name of the tab

当我在选项卡的名称中有一个拼写错误时,我遇到了这个错误。在您的情况下,“类数据”与选项卡的名称不匹配

回答by Tan Phan

String range = "Class Data!A2:A4";

String range = "Class Data!A2:A4";

The Class Datais your worksheet's name, FYI: the name on the tab at the bottom, the default one is "Sheet1". Replace Class Datawith the one you want to work with.

Class Data是您的工作表的名称,仅供参考:底部选项卡上的名称,默认为“Sheet1”。替换Class Data为您要使用的那个。