I am trying to access Google spreadsheets using a spreadsheet example. When I run the example code it worked fine. I just change the SpreadsheetId and 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$1.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();
4 个解决方案
#1
61
Try replacing Class Data!A2:A4
with A2:A4
尝试更换Class Data!A2:A4,A2:A4
#2
10
If you look at the sheet itself you 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";
如果您查看工作表本身,您会注意到工作表标题为“类数据”。所以只需将工作表的名称放在“Class Data”中。示例:String range =“SheetName!A1:C”;
#3
2
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
错误:无法解析范围:Emmet!A2:C12
I had to manually create the sheet named Emmett
in the spreadsheet and then it worked like a charm.
我不得不在电子表格中手动创建名为Emmett的工作表,然后它就像一个魅力。
#4
1
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
当我在选项卡的名称中输入错误时,我遇到了这个错误。在您的情况下,“类数据”与选项卡的名称不匹配
#1
61
Try replacing Class Data!A2:A4
with A2:A4
尝试更换Class Data!A2:A4,A2:A4
#2
10
If you look at the sheet itself you 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";
如果您查看工作表本身,您会注意到工作表标题为“类数据”。所以只需将工作表的名称放在“Class Data”中。示例:String range =“SheetName!A1:C”;
#3
2
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
错误:无法解析范围:Emmet!A2:C12
I had to manually create the sheet named Emmett
in the spreadsheet and then it worked like a charm.
我不得不在电子表格中手动创建名为Emmett的工作表,然后它就像一个魅力。
#4
1
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
当我在选项卡的名称中输入错误时,我遇到了这个错误。在您的情况下,“类数据”与选项卡的名称不匹配