Google apps script 如何在应用程序脚本中动态保护google sheets中的特定范围?
我知道如何通过应用程序脚本保护谷歌表单中的范围,但我想动态保护特定的范围,我们如何做到这一点 我曾尝试在数据来自BigQuery时设置保护,但在使用过滤器后,它不允许更新当前工作表,因为它受保护Google apps script 如何在应用程序脚本中动态保护google sheets中的特定范围?,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我知道如何通过应用程序脚本保护谷歌表单中的范围,但我想动态保护特定的范围,我们如何做到这一点 我曾尝试在数据来自BigQuery时设置保护,但在使用过滤器后,它不允许更新当前工作表,因为它受保护 var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getRange('A1:L28').activate(); var protection = spreadsheet.getRange('A9').protect(); pr
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1:L28').activate();
var protection = spreadsheet.getRange('A9').protect();
protection.removeEditors(['nikhil.doda@mediaagility.com']);
我希望只有在数据到达google电子表格后,输出才会受到保护,然后才能过滤数据并更改表格中的数据,而不会出现受保护的表格错误如果您从外部将Bigquery数据插入google电子表格,则无法使用应用程序脚本检测更新事件 要插入BigQuery数据时,您可以执行以下操作:
function myFunction() {
var spreadsheet = SpreadsheetApp.getActive();
//remove all protections
spreadsheet.getProtections(SpreadsheetApp.ProtectionType.RANGE).forEach(function(e){e.remove()});
//not sure what you want to do with the following line
spreadsheet.getRange('A1:L28').activate();
// Retrieve your Bigquery data and proceed as required
queryResults = BigQuery.Jobs.query(queryRequest, projectNumber);
...
//After finishing the query, protect the range
//provided you want to protect only cell 'A9' in the active sheet
var protection = spreadsheet.getActiveSheet().getRange('A9').protect();
protection.removeEditors(['nikhil.doda@mediaagility.com']);
}