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
Google spreadsheet API, 400 error bad request : unable to parse range
提问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:A4
with A2:A4
尝试替换Class Data!A2:A4
为A2:A4
回答by Boom3k
回答by slifszyc
I was trying to add some data to a sheet named Emmett
that 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 Emmett
in 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 Data
is your worksheet's name, FYI: the name on the tab at the bottom, the default one is "Sheet1". Replace Class Data
with the one you want to work with.
这Class Data
是您的工作表的名称,仅供参考:底部选项卡上的名称,默认为“Sheet1”。替换Class Data
为您要使用的那个。