Java Code Examples for com.google.api.services.sheets.v4.model.GridRange#setStartRowIndex()

The following examples show how to use com.google.api.services.sheets.v4.model.GridRange#setStartRowIndex() . 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: GoogleSheetsAddChartCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static void addPieChart(ChartSpec chartSpec, GoogleChart model) {
    Integer sheetId = Optional.ofNullable(model.getSheetId())
                              .orElse(0);

    Integer sourceSheetId = Optional.ofNullable(model.getSourceSheetId())
                                    .orElse(sheetId);

    GoogleChart.PieChart pieChart = model.getPieChart();

    PieChartSpec pieChartSpec = new PieChartSpec();
    pieChartSpec.setLegendPosition(pieChart.getLegendPosition());
    pieChartSpec.setDomain(new ChartData().setSourceRange(getDomainSourceRange(sourceSheetId, pieChart.getDomainRange())));

    ChartSourceRange sourceRange = new ChartSourceRange();
    GridRange gridRange = new GridRange();
    gridRange.setSheetId(sourceSheetId);
    RangeCoordinate coordinates = RangeCoordinate.fromRange(pieChart.getDataRange());
    gridRange.setStartRowIndex(coordinates.getRowStartIndex());
    gridRange.setEndRowIndex(coordinates.getRowEndIndex());
    gridRange.setStartColumnIndex(coordinates.getColumnStartIndex());
    gridRange.setEndColumnIndex(coordinates.getColumnEndIndex());
    sourceRange.setSources(Collections.singletonList(gridRange));

    pieChartSpec.setSeries(new ChartData().setSourceRange(sourceRange));

    chartSpec.setPieChart(pieChartSpec);
}
 
Example 2
Source File: GoogleSheetsAddChartCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static ChartSourceRange getDomainSourceRange(int sourceSheetId, String domainRange) {
    ChartSourceRange domainSourceRange = new ChartSourceRange();
    GridRange domainGridRange = new GridRange();
    domainGridRange.setSheetId(sourceSheetId);
    RangeCoordinate coordinate = RangeCoordinate.fromRange(domainRange);
    domainGridRange.setStartRowIndex(coordinate.getRowStartIndex());
    domainGridRange.setEndRowIndex(coordinate.getRowEndIndex());
    domainGridRange.setStartColumnIndex(coordinate.getRowStartIndex());
    domainGridRange.setEndColumnIndex(coordinate.getColumnEndIndex());
    domainSourceRange.setSources(Collections.singletonList(domainGridRange));
    return domainSourceRange;
}
 
Example 3
Source File: GoogleSheetsAddPivotTableCustomizer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
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);
}