com.google.api.services.sheets.v4.model.Request Java Examples
The following examples show how to use
com.google.api.services.sheets.v4.model.Request.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleSpreadsheetWriter.java From SPDS with Eclipse Public License 2.0 | 7 votes |
public static void createSheet(List<Object> headers) throws IOException, GeneralSecurityException{ if(onlyOnce) return; onlyOnce = true; Sheets service = getService(); String sheetID = getGitRepositoryState().commitId; List<Request> requests = new ArrayList<>(); AddSheetRequest addSheet = new AddSheetRequest(); addSheet.setProperties(new SheetProperties().setTitle(sheetID)); requests.add(new Request().setAddSheet(addSheet)); BatchUpdateSpreadsheetRequest requestBody = new BatchUpdateSpreadsheetRequest(); requestBody.setRequests(requests); service.spreadsheets().batchUpdate(SPREADSHEET_ID, requestBody).execute(); ArrayList<List<Object>> rows = Lists.newArrayList(); rows.add(headers); ValueRange body = new ValueRange().setValues(Arrays.asList(headers)); service.spreadsheets().values().append(SPREADSHEET_ID, sheetID, body).setValueInputOption("USER_ENTERED") .execute(); }
Example #2
Source File: GoogleSheetsResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Path("/update") @PATCH @Consumes(MediaType.TEXT_PLAIN) public Response updateSheet(@QueryParam("spreadsheetId") String spreadsheetId, String title) { BatchUpdateSpreadsheetRequest request = new BatchUpdateSpreadsheetRequest() .setIncludeSpreadsheetInResponse(true) .setRequests(Collections .singletonList(new Request().setUpdateSpreadsheetProperties(new UpdateSpreadsheetPropertiesRequest() .setProperties(new SpreadsheetProperties().setTitle(title)) .setFields("title")))); final Map<String, Object> headers = new HashMap<>(); headers.put("CamelGoogleSheets.spreadsheetId", spreadsheetId); headers.put("CamelGoogleSheets.batchUpdateSpreadsheetRequest", request); producerTemplate.requestBodyAndHeaders("google-sheets://spreadsheets/batchUpdate", null, headers); return Response.ok().build(); }
Example #3
Source File: BaseTest.java From java-samples with Apache License 2.0 | 6 votes |
protected void populateValuesWithStrings(String spreadsheetId) throws IOException { List<Request> requests = new ArrayList<>(); requests.add(new Request().setRepeatCell(new RepeatCellRequest() .setRange(new GridRange() .setSheetId(0) .setStartRowIndex(0) .setEndRowIndex(10) .setStartColumnIndex(0) .setEndColumnIndex(10)) .setCell(new CellData() .setUserEnteredValue(new ExtendedValue() .setStringValue("Hello"))) .setFields("userEnteredValue"))); BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest() .setRequests(requests); service.spreadsheets().batchUpdate(spreadsheetId, body).execute(); }
Example #4
Source File: BaseTest.java From java-samples with Apache License 2.0 | 6 votes |
protected void populateValuesWithNumbers(String spreadsheetId) throws IOException { List<Request> requests = new ArrayList<>(); requests.add(new Request().setRepeatCell(new RepeatCellRequest() .setRange(new GridRange() .setSheetId(0) .setStartRowIndex(0) .setEndRowIndex(10) .setStartColumnIndex(0) .setEndColumnIndex(10)) .setCell(new CellData() .setUserEnteredValue(new ExtendedValue() .setNumberValue(1337D))) .setFields("userEnteredValue"))); BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest() .setRequests(requests); service.spreadsheets().batchUpdate(spreadsheetId, body).execute(); }
Example #5
Source File: GoogleSheetsAddChartCustomizer.java From syndesis with Apache License 2.0 | 5 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final GoogleChart model = exchange.getIn().getBody(GoogleChart.class); if (model != null) { if (ObjectHelper.isNotEmpty(model.getSpreadsheetId())) { spreadsheetId = model.getSpreadsheetId(); } if (ObjectHelper.isNotEmpty(model.getTitle())) { title = model.getTitle(); } if (ObjectHelper.isNotEmpty(model.getSubtitle())) { subtitle = model.getSubtitle(); } } BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest(); batchUpdateRequest.setIncludeSpreadsheetInResponse(true); batchUpdateRequest.setRequests(new ArrayList<>()); AddChartRequest addChartRequest = new AddChartRequest(); batchUpdateRequest.getRequests().add(new Request().setAddChart(addChartRequest)); ChartSpec chartSpec = createChartSpec(title, subtitle); if (model != null) { addChartRequest.setChart(createEmbeddedChart(model, chartSpec)); if (model.getBasicChart() != null) { addBasicChart(chartSpec, model); } else if (model.getPieChart() != null) { addPieChart(chartSpec, model); } } else { addChartRequest.setChart(createEmptyChart(chartSpec)); } in.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, spreadsheetId); in.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest", batchUpdateRequest); }
Example #6
Source File: GoogleSheetsUpdateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final GoogleSpreadsheet model = exchange.getIn().getBody(GoogleSpreadsheet.class); if (model != null) { if (ObjectHelper.isNotEmpty(model.getSpreadsheetId())) { spreadsheetId = model.getSpreadsheetId(); } if (ObjectHelper.isNotEmpty(model.getTitle())) { title = model.getTitle(); } if (ObjectHelper.isNotEmpty(model.getTimeZone())) { timeZone = model.getTimeZone(); } if (ObjectHelper.isNotEmpty(model.getLocale())) { locale = model.getLocale(); } } BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest(); batchUpdateRequest.setIncludeSpreadsheetInResponse(true); batchUpdateRequest.setRequests(new ArrayList<>()); List<String> fields = new ArrayList<>(); SpreadsheetProperties spreadsheetProperties = getSpreadsheetProperties(fields); if (ObjectHelper.isNotEmpty(fields)) { UpdateSpreadsheetPropertiesRequest updatePropertiesRequest = new UpdateSpreadsheetPropertiesRequest(); updatePropertiesRequest.setProperties(spreadsheetProperties); updatePropertiesRequest.setFields(String.join(",", fields)); batchUpdateRequest.getRequests().add(new Request().setUpdateSpreadsheetProperties(updatePropertiesRequest)); } if (model != null && ObjectHelper.isNotEmpty(model.getSheets())) { for (GoogleSheet sheet : model.getSheets()) { UpdateSheetPropertiesRequest updateSheetPropertiesRequest = new UpdateSheetPropertiesRequest(); SheetProperties properties = new SheetProperties(); properties.setSheetId(sheet.getSheetId()); properties.setIndex(sheet.getIndex()); properties.setTitle(sheet.getTitle()); updateSheetPropertiesRequest.setProperties(properties); updateSheetPropertiesRequest.setFields("title"); batchUpdateRequest.getRequests().add(new Request().setUpdateSheetProperties(updateSheetPropertiesRequest)); } } in.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, spreadsheetId); in.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest", batchUpdateRequest); }
Example #7
Source File: GoogleSheetsAddPivotTableCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final GooglePivotTable model = exchange.getIn().getBody(GooglePivotTable.class); if (model != null && ObjectHelper.isNotEmpty(model.getSpreadsheetId())) { spreadsheetId = model.getSpreadsheetId(); } BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest(); batchUpdateRequest.setIncludeSpreadsheetInResponse(true); batchUpdateRequest.setRequests(new ArrayList<>()); UpdateCellsRequest updateCellsRequest = new UpdateCellsRequest(); updateCellsRequest.setFields("pivotTable"); batchUpdateRequest.getRequests().add(new Request().setUpdateCells(updateCellsRequest)); RowData rowData = new RowData(); PivotTable pivotTable = new PivotTable(); if (model != null) { Integer defaultSheetId = Optional.ofNullable(model.getSheetId()).orElse(0); pivotTable.setValueLayout(model.getValueLayout()); GridRange sourceRange = new GridRange(); sourceRange.setSheetId(Optional.ofNullable(model.getSourceSheetId()).orElse(defaultSheetId)); RangeCoordinate coordinate = RangeCoordinate.fromRange(model.getSourceRange()); sourceRange.setStartRowIndex(coordinate.getRowStartIndex()); sourceRange.setEndRowIndex(coordinate.getRowEndIndex()); sourceRange.setStartColumnIndex(coordinate.getColumnStartIndex()); sourceRange.setEndColumnIndex(coordinate.getColumnEndIndex()); pivotTable.setSource(sourceRange); addRowGroups(pivotTable, model); addColumnGroups(pivotTable, model); addValueGroups(pivotTable, model); } updateCellsRequest.setStart(getStartCoordinate(pivotTable, model)); rowData.setValues(Collections.singletonList(new CellData().setPivotTable(pivotTable))); updateCellsRequest.setRows(Collections.singletonList(rowData)); in.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, spreadsheetId); in.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest", batchUpdateRequest); }
Example #8
Source File: GoogleSheetsLiveTest.java From tutorials with MIT License | 4 votes |
@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(); }