简体   繁体   中英

Error trying to write a row in google sheets using API v4

I'm trying to write a row to a sheet using java and Google Sheets API v4. I'm getting an error that I just can't understand. Any help would be greatly appreciated!

The values passed are:

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]]}

Here is the trouble code:

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

And the result:

{
  "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"
}

Got this error due to character issues in the sheet title. Removing spaces, dashes, and colons in the sheet titles and replacing them with underscores fixed it.

I think sRange should be using A1 notation :

Something that looks like:

SheetName!A1:B2
Sheet1!A1

Check the link for more info.

Change your Sheet name to some simple version of it (without special symbols). Helped in my case.

I have been on this for some time now, in my case i was trying to update more than 2 fields in a row and i specified range as A1:B1 this only depicts 2 rows to be updated. I changed it to just A1 and it worked.

So let your range be:

SheetName!A1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM