google-api-java-client-services
google-api-java-client-services copied to clipboard
Write selectively to a range isn’t working
Environment details
- OS type and version: N/A
- Java version: 1.8
- google-api-client version(s): v4-rev20191115-1.30.3
Steps to reproduce
- Starting from the Sheets Java quickstart [2], use the below code in the main function.
- Create a Spreadsheet and replace its ID in the code above.
- Run the code.
Expected behavior: It should update cells A1, B1, C1, E1 and G1. Leaving D1 and F1 as they were.
Actual behavior: It’s updating cells A1, B1, C1, D1 and E1.
Code example
Sheets sheetService = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)).setApplicationName(APPLICATION_NAME).build();
String range1 = "Sheet1!A1:G1";
List<List<Object>> values = Arrays.asList(Arrays.asList("1", "2", "3", null, "5", null, “7”));
ValueRange vRange = new ValueRange();
vRange.setRange(range1);
vRange.setValues(values);
vRange.setMajorDimension("ROWS");
try {
System.out.println(sheetService.spreadsheets().values().update("[SPREADSHEET-ID]", range1, vRange)
.setValueInputOption("USER_ENTERED")
.setResponseDateTimeRenderOption("FORMATTED_STRING")
.execute().toPrettyString());
} catch (IOException e) {
e.printStackTrace();
}
External references such as API reference guides
[1] https://developers.google.com/resources/api-libraries/documentation/sheets/v4/java/latest/ [2] https://developers.google.com/sheets/api/quickstart/java [3] https://developers.google.com/sheets/api/samples/writing#write_selectively_to_a_range [4] https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update?apix_params=%7B%22spreadsheetId%22%3A%221A6RjjlOSQ7zRBYEJUhakv3IyqT-R44XcnFrBW0DFfZk%22%2C%22range%22%3A%22Sheet2!A1%3AG1%22%2C%22responseDateTimeRenderOption%22%3A%22FORMATTED_STRING%22%2C%22valueInputOption%22%3A%22USER_ENTERED%22%2C%22prettyPrint%22%3Atrue%2C%22resource%22%3A%7B%22majorDimension%22%3A%22ROWS%22%2C%22values%22%3A%5B%5B%221%22%2C%222%22%2C%223%22%2Cnull%2C%225%22%2Cnull%2C%227%22%5D%5D%7D%7D
Any additional information below
- According to Sheets API documentation writing selectively to a range is supported [3].
- From “Try this API” it’s working as expected with this request [4].
All of your links are for Sheets. I think you might want to open an issue under: https://github.com/googleapis/google-api-java-client-services If I missed something please feel free to reopen.
Closing this issue as we are unable to provide adequate customer support through this forum. If you feel there is a bug or a feature request associated with this ticket, please open a new issue. Otherwise, https://cloud.google.com/support is best able to provide timely answers to API-specific questions.