Search in sources :

Example 1 with ValueRange

use of com.google.api.services.sheets.v4.model.ValueRange in project collect by opendatakit.

the class SheetsHelperTest method updateRowTest.

@Test
public void updateRowTest() throws IOException {
    ValueRange valueRange = new ValueRange();
    sheetsHelper.updateRow("spreadsheet_id", "sheet_name!A1", valueRange);
    verify(sheetsService).updateRow("spreadsheet_id", "sheet_name!A1", valueRange);
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ValueRange

use of com.google.api.services.sheets.v4.model.ValueRange in project collect by opendatakit.

the class SheetsHelperTest method insertRowTest.

@Test
public void insertRowTest() throws IOException {
    ValueRange valueRange = new ValueRange();
    sheetsHelper.insertRow("spreadsheet_id", "sheet_name", valueRange);
    verify(sheetsService).insertRow("spreadsheet_id", "sheet_name", valueRange);
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ValueRange

use of com.google.api.services.sheets.v4.model.ValueRange in project tutorials by eugenp.

the class GoogleSheetsIntegrationTest method whenWriteSheet_thenReadSheetOk.

@Test
public void whenWriteSheet_thenReadSheetOk() throws IOException {
    ValueRange body = new ValueRange().setValues(Arrays.asList(Arrays.asList("Expenses January"), Arrays.asList("books", "30"), Arrays.asList("pens", "10"), Arrays.asList("Expenses February"), Arrays.asList("clothes", "20"), Arrays.asList("shoes", "5")));
    UpdateValuesResponse result = sheetsService.spreadsheets().values().update(SPREADSHEET_ID, "A1", body).setValueInputOption("RAW").execute();
    List<ValueRange> data = new ArrayList<>();
    data.add(new ValueRange().setRange("D1").setValues(Arrays.asList(Arrays.asList("January Total", "=B2+B3"))));
    data.add(new ValueRange().setRange("D4").setValues(Arrays.asList(Arrays.asList("February Total", "=B5+B6"))));
    BatchUpdateValuesRequest batchBody = new BatchUpdateValuesRequest().setValueInputOption("USER_ENTERED").setData(data);
    BatchUpdateValuesResponse batchResult = sheetsService.spreadsheets().values().batchUpdate(SPREADSHEET_ID, batchBody).execute();
    List<String> ranges = Arrays.asList("E1", "E4");
    BatchGetValuesResponse readResult = sheetsService.spreadsheets().values().batchGet(SPREADSHEET_ID).setRanges(ranges).execute();
    ValueRange januaryTotal = readResult.getValueRanges().get(0);
    assertThat(januaryTotal.getValues().get(0).get(0)).isEqualTo("40");
    ValueRange febTotal = readResult.getValueRanges().get(1);
    assertThat(febTotal.getValues().get(0).get(0)).isEqualTo("25");
    ValueRange appendBody = new ValueRange().setValues(Arrays.asList(Arrays.asList("Total", "=E1+E4")));
    AppendValuesResponse appendResult = sheetsService.spreadsheets().values().append(SPREADSHEET_ID, "A1", appendBody).setValueInputOption("USER_ENTERED").setInsertDataOption("INSERT_ROWS").setIncludeValuesInResponse(true).execute();
    ValueRange total = appendResult.getUpdates().getUpdatedData();
    assertThat(total.getValues().get(0).get(1)).isEqualTo("65");
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) BatchUpdateValuesResponse(com.google.api.services.sheets.v4.model.BatchUpdateValuesResponse) BatchGetValuesResponse(com.google.api.services.sheets.v4.model.BatchGetValuesResponse) ArrayList(java.util.ArrayList) AppendValuesResponse(com.google.api.services.sheets.v4.model.AppendValuesResponse) BatchUpdateValuesRequest(com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest) BatchUpdateValuesResponse(com.google.api.services.sheets.v4.model.BatchUpdateValuesResponse) UpdateValuesResponse(com.google.api.services.sheets.v4.model.UpdateValuesResponse) Test(org.junit.Test)

Example 4 with ValueRange

use of com.google.api.services.sheets.v4.model.ValueRange in project jbpm-work-items by kiegroup.

the class ReadSheetValuesWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> results = new HashMap<String, Object>();
    String paramSheetId = (String) workItem.getParameter("SheetId");
    // to learn google spreadsheet ranges go to
    // https://developers.google.com/sheets/api/guides/concepts
    String paramRange = (String) workItem.getParameter("Range");
    try {
        Sheets service = auth.getSheetsService(appName, clientSecret);
        ValueRange sheetResponse = service.spreadsheets().values().get(paramSheetId, paramRange).execute();
        List<List<Object>> values = sheetResponse.getValues();
        results.put(RESULTS_VALUES, values);
    } catch (Exception e) {
        handleException(e);
    }
    workItemManager.completeWorkItem(workItem.getId(), results);
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) HashMap(java.util.HashMap) List(java.util.List) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 5 with ValueRange

use of com.google.api.services.sheets.v4.model.ValueRange in project repairnator by Spirals-Team.

the class GoogleSpreadSheetFactory method insertData.

public static void insertData(List<List<Object>> dataRows, Sheets sheets, String range, Logger logger) {
    ValueRange valueRange = new ValueRange();
    valueRange.setValues(dataRows);
    try {
        AppendValuesResponse response = sheets.spreadsheets().values().append(GoogleSpreadSheetFactory.getSpreadsheetID(), range, valueRange).setInsertDataOption("INSERT_ROWS").setValueInputOption("USER_ENTERED").execute();
        if (response != null && response.getUpdates().getUpdatedCells() > 0) {
            logger.debug("Data have been inserted in Google Spreadsheet.");
        }
    } catch (IOException e) {
        logger.error("An error occurred while inserting data in Google Spreadsheet.", e);
    }
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) AppendValuesResponse(com.google.api.services.sheets.v4.model.AppendValuesResponse) IOException(java.io.IOException)

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