I am trying to implement the Google sheets API writing feature into my app using following code from this web page but unable to figure out what and how to assign a value to a ValueRange variable.
public class SheetsExample {
public static void main(String args[]) throws IOException,
GeneralSecurityException {
// The ID of the spreadsheet to update.
String spreadsheetId = "my-spreadsheet-id"; // TODO: Update placeholder value.
//The A1 notation of the values to update.
String range = "my-range"; // TODO: Update placeholder value.
// TODO: Assign values to desired fields of `requestBody`. All existing
// fields will be replaced:
ValueRange requestBody = new ValueRange();
Sheets sheetsService = createSheetsService();
Sheets.Spreadsheets.Values.Update request =
sheetsService.spreadsheets().values().update(spreadsheetId, range, requestBody);
UpdateValuesResponse response = request.execute();
// TODO: Change code below to process the `response` object:
System.out.println(response);
}
public static Sheets createSheetsService() throws IOException, GeneralSecurityException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
// TODO: Change placeholder below to generate authentication credentials. See
// https://developers.google.com/sheets/quickstart/java#step_3_set_up_the_sample
//
// Authorize using one of the following scopes:
// "https://www.googleapis.com/auth/drive"
// "https://www.googleapis.com/auth/drive.file"
// "https://www.googleapis.com/auth/spreadsheets"
GoogleCredential credential = null;
return new Sheets.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google-SheetsSample/0.1")
.build();
}
}