use of com.google.api.services.sheets.v4.model.ValueRange in project teiid by teiid.
the class SheetsAPI method insert.
/**
* Insert row into spreadsheet
* @param spreadsheetKey key that identifies spreadsheet
* @param pairs key that identifies worksheet
* @param worksheet name - value pair that should be inserted into spreadsheet
* @return 1 if the row is successfully inserted
*/
public UpdateResult insert(String spreadsheetId, Map<String, Object> pairs, Worksheet worksheet) {
ValueRange content = new ValueRange();
List<Object> row = new ArrayList<>();
for (String label : worksheet.getColumns().keySet()) {
Object value = pairs.get(label);
if (value != null) {
if (value instanceof String) {
// $NON-NLS-1$
value = "'" + value;
} else if (!(value instanceof Boolean || value instanceof Double)) {
value = value.toString();
}
// else directly supported
}
row.add(value);
}
content.setValues(Arrays.asList(row));
try {
service.spreadsheets().values().append(spreadsheetId, worksheet.getName(), content).setValueInputOption(// $NON-NLS-1$ -- TODO: this could be configurable
"USER_ENTERED").execute();
} catch (IOException e) {
throw new SpreadsheetOperationException("Error inserting spreadsheet row", e);
}
return new UpdateResult(1, 1);
}
use of com.google.api.services.sheets.v4.model.ValueRange in project selenium_java by sergueik.
the class Quickstart method main.
public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Sheets service = getSheetsService();
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
String range = "Class Data!A2:E";
ValueRange response = service.spreadsheets().values().get(spreadsheetId, range).execute();
List<List<Object>> values = response.getValues();
if (values == null || values.size() == 0) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.printf("%s, %s\n", row.get(0), row.get(4));
}
}
}
use of com.google.api.services.sheets.v4.model.ValueRange in project jbpm-work-items by kiegroup.
the class GoogleSheetsWorkitemHandlerTest method setUp.
@Before
public void setUp() {
try {
ValueRange valueRange = new ValueRange();
List<List<Object>> testValues = new ArrayList<>();
List<Object> testRowValues = new ArrayList<>();
testRowValues.add("testValueOne");
testRowValues.add("testValueTwo");
testValues.add(testRowValues);
valueRange.setValues(testValues);
when(auth.getSheetsService(anyString(), anyString())).thenReturn(sheetsClient);
when(sheetsClient.spreadsheets()).thenReturn(spreadsheets);
when(spreadsheets.values()).thenReturn(spreasheetsValues);
when(spreasheetsValues.get(anyString(), anyString())).thenReturn(spreasheetsValuesGet);
when(spreasheetsValuesGet.execute()).thenReturn(valueRange);
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations