Google Sheet API,执行AddProtectedRangeRequest

Google sheet API, executing AddProtectedRangeRequest(Google Sheet API,执行AddProtectedRangeRequest)

本文介绍了Google Sheet API,执行AddProtectedRangeRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于:https://developers.google.com/sheets/api/samples/ranges

如何执行Google Sheet API,执行AddProtectedRangeRequest?

 void addRangeRestriction(final String sheetId, final Sheets sheetService) throws IOException {

    AddProtectedRangeRequest addProtectedRangeRequest = new AddProtectedRangeRequest();


    var gridRange = new GridRange();
        gridRange.setSheetId(1);
        gridRange.setStartColumnIndex(1);
        gridRange.setEndColumnIndex(1);
        gridRange.setStartRowIndex(2);
        gridRange.setEndRowIndex(2);

    var protectedRange = new ProtectedRange();
        protectedRange.setRange(gridRange);
        protectedRange.setWarningOnly(true);

    var request = new Request()
            .setAddProtectedRange(new AddProtectedRangeRequest()
                    .setProtectedRange(new ProtectedRange()
                            .setRange(gridRange)
                            .setRequestingUserCanEdit(false)));


    addProtectedRangeRequest.setProtectedRange(protectedRange);

    // TODO: ... ??
}

--

我可以为

   var batchUpdateSpreadsheetRequest = new BatchUpdateSpreadsheetRequest();

如下: return sheetService.spreadsheets().batchUpdate(sheetId, batchUpdateSpreadsheetRequest).execute();

但不适用于AddProtectedRangeRequest..一个

推荐答案

BatchUpdateSpreadsheetRequest接受要执行的请求列表。您可以将请求添加到ArrayList,然后将其分配给BatchUpdateSpreadsheetRequest

您可以通过这种方式将您希望按顺序执行的所有请求添加到单个BatchUpdateSpreadsheetRequest中。将按照列表中指定的顺序应用请求。如果任何请求无效,则不会应用任何请求。

List<Request> requests = new ArrayList<>();
requests.add(request)

var batchUpdateSpreadsheetRequest = new BatchUpdateSpreadsheetRequest();
batchUpdateSpreadsheetRequest.setRequests(requests);

return sheetService.spreadsheets()
    .batchUpdate(sheetId, batchUpdateSpreadsheetRequest)
    .execute();

这篇关于Google Sheet API,执行AddProtectedRangeRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Google Sheet API,执行AddProtectedRangeRequest

基础教程推荐