Search in sources :

Example 6 with ValueRange

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);
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) SpreadsheetOperationException(org.teiid.translator.google.api.SpreadsheetOperationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UpdateResult(org.teiid.translator.google.api.result.UpdateResult)

Example 7 with ValueRange

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));
        }
    }
}
Also used : List(java.util.List) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 8 with ValueRange

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());
    }
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Aggregations

ValueRange (com.google.api.services.sheets.v4.model.ValueRange)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 Sheets (com.google.api.services.sheets.v4.Sheets)2 AppendValuesResponse (com.google.api.services.sheets.v4.model.AppendValuesResponse)2 IOException (java.io.IOException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BatchGetValuesResponse (com.google.api.services.sheets.v4.model.BatchGetValuesResponse)1 BatchUpdateValuesRequest (com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest)1 BatchUpdateValuesResponse (com.google.api.services.sheets.v4.model.BatchUpdateValuesResponse)1 UpdateValuesResponse (com.google.api.services.sheets.v4.model.UpdateValuesResponse)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 SpreadsheetOperationException (org.teiid.translator.google.api.SpreadsheetOperationException)1 UpdateResult (org.teiid.translator.google.api.result.UpdateResult)1