【问题标题】:App-Scripts- How to unprotect series of repeated ranges at once?App-Scripts-如何一次取消保护一系列重复范围?
【发布时间】:2021-07-09 21:43:56
【问题描述】:

我想保护我的整张工作表,但只想要一些不受保护的范围,这些范围是重复的系列。所以我不想创建一个新范围并将其添加到未受保护的范围内。有没有更短的方法。只要给你们一个广泛的画面,我有 40 行和“n”列的动态工作表。但我想从 Col3 C5:F35 unprotected 开始,然后完全跳过 4 列,然后再 K5:N35 unprotected 等等,直到 lastCol。我有大量的列,因此手动执行此操作几乎是不可能的。对此事的帮助将不胜感激。我附上了一张图片,可能有助于消除一些困惑。

spreadsheet screenshot attached

【问题讨论】:

标签: google-apps-script google-sheets google-sheets-formula spreadsheet


【解决方案1】:

我建议使用 Google 脚本,而不是保护范围,而是使用它来保护范围,如下所示:

function protectColumns() {
  let ss = SpreadsheetApp.getActive();
  let spreadsheet = ss.getSheets()[0];

  let lastColumn = spreadsheet.getLastColumn();
  let lastRow = spreadsheet.getLastColumn();

  let range = spreadsheet.getRange(1, 1, lastRow, 2); // Sets the range from Row 1 Column1 to Last Row Column 2
  let protection = range.protect().setDescription('Sample protected range');

  for(let i=7; i<lastColumn; i+=8) { //Starting at column 7, Protect 4 rows, skip 4 rows, repeat
    range = spreadsheet.getRange(1, i, lastRow, 4);
    range.protect().setDescription('Sample protected range');
  }
}

这应该做我认为你想要的。它保护前 2 行,跳过接下来的 4 行,保护接下来的 4 行,然后重复。我只会警告它可能会错过保护列的最后一部分。如果有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-27
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    相关资源
    最近更新 更多