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();
解决方案
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();
相关文章