use of com.google.api.services.sheets.v4.model.SpreadsheetProperties in project tutorials by eugenp.
the class GoogleSheetsIntegrationTest method whenUpdateSpreadSheetTitle_thenOk.
@Test
public void whenUpdateSpreadSheetTitle_thenOk() throws IOException {
UpdateSpreadsheetPropertiesRequest updateRequest = new UpdateSpreadsheetPropertiesRequest().setFields("*").setProperties(new SpreadsheetProperties().setTitle("Expenses"));
CopyPasteRequest copyRequest = new CopyPasteRequest().setSource(new GridRange().setSheetId(0).setStartColumnIndex(0).setEndColumnIndex(2).setStartRowIndex(0).setEndRowIndex(1)).setDestination(new GridRange().setSheetId(1).setStartColumnIndex(0).setEndColumnIndex(2).setStartRowIndex(0).setEndRowIndex(1)).setPasteType("PASTE_VALUES");
List<Request> requests = new ArrayList<>();
requests.add(new Request().setCopyPaste(copyRequest));
requests.add(new Request().setUpdateSpreadsheetProperties(updateRequest));
BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests);
sheetsService.spreadsheets().batchUpdate(SPREADSHEET_ID, body).execute();
}
use of com.google.api.services.sheets.v4.model.SpreadsheetProperties in project tutorials by eugenp.
the class GoogleSheetsIntegrationTest method whenCreateSpreadSheet_thenIdOk.
@Test
public void whenCreateSpreadSheet_thenIdOk() throws IOException {
Spreadsheet spreadSheet = new Spreadsheet().setProperties(new SpreadsheetProperties().setTitle("My Spreadsheet"));
Spreadsheet result = sheetsService.spreadsheets().create(spreadSheet).execute();
assertThat(result.getSpreadsheetId()).isNotNull();
}
use of com.google.api.services.sheets.v4.model.SpreadsheetProperties in project collect by opendatakit.
the class SheetsHelper method getSpreadsheet.
/**
* Checks whether the selected google account has sufficient permissions
* to modify the given spreadsheetId. If yes, then returns complete spreadsheet
* otherwise throws exception
*/
public Spreadsheet getSpreadsheet(String spreadsheetId) throws IOException {
/*
* Read permission check
*
* To check read permissions, we are trying to fetch the complete spreadsheet using the
* given spreadsheet id
*/
// fetching the google spreadsheet
Spreadsheet spreadsheet = sheetsService.getSpreadsheet(spreadsheetId);
String spreadsheetFileName = spreadsheet.getProperties().getTitle();
/*
* Write permission check
*
* To check write permissions, we are trying to overwrite the name of the spreadsheet with
* the same name
*
* Todo 22/3/17 Find a better way to check the write permissions
*/
// creating a request to update name of spreadsheet
SpreadsheetProperties sheetProperties = new SpreadsheetProperties().setTitle(spreadsheetFileName);
List<Request> requests = new ArrayList<>();
requests.add(new Request().setUpdateSpreadsheetProperties(new UpdateSpreadsheetPropertiesRequest().setProperties(sheetProperties).setFields("title")));
// updating the spreadsheet with the given id
sheetsService.batchUpdate(spreadsheetId, requests);
return spreadsheet;
}
use of com.google.api.services.sheets.v4.model.SpreadsheetProperties in project collect by opendatakit.
the class SheetsHelperTest method getSpreadsheetTest.
@Test
public void getSpreadsheetTest() throws IOException {
Spreadsheet mockedSpreadsheet = mock(Spreadsheet.class);
SpreadsheetProperties mockedProperties = mock(SpreadsheetProperties.class);
doReturn("sheet_title").when(mockedProperties).getTitle();
doReturn(mockedProperties).when(mockedSpreadsheet).getProperties();
doReturn(mockedSpreadsheet).when(sheetsService).getSpreadsheet("spreadsheet_id");
Spreadsheet spreadsheet = sheetsHelper.getSpreadsheet("spreadsheet_id");
assertEquals(mockedSpreadsheet, spreadsheet);
assertBatchUpdateCalled(1);
}
Aggregations