使用Google Apps脚本的Google电子表格用户权限

时间:2018-02-07 17:39:14

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

我无法使用GOOGLE APPS SCRIPT CODE复制这些操作的结果(参见图片)。

以下是行动:

使用Google Spreadsheets打开SpreadSheet

右键单击 - >保护范围......

点击此

enter image description here

然后点击此

enter image description here

并且

enter image description here

尝试此代码后,我获得了 NO 的成功:

parse(value: string, fractionSize: number = 2): number {
  let val = value.replace(/([^0-9.])+/ig, '');
  let [ integer, fraction = "" ] = (val || "").split(this.DECIMAL_SEPARATOR);
  integer = integer.replace(new RegExp(this.THOUSANDS_SEPARATOR, "g"), "");
  fraction = parseInt(fraction, 10) > 0 && fractionSize > 0
    ? this.DECIMAL_SEPARATOR + (fraction + PADDING).substring(0, fractionSize)
    : "";
  let result = `${integer}${fraction}`;
  // at this point result = "100.55";
  result = parseFloat(result); // this refuses to compile saying "Type 'number' is not assignable │ to type 'string'"
  return result;
}

1 个答案:

答案 0 :(得分:0)

这里解决了这个问题。

在我的具体情况下,权限为"表格为#34; NOT"按范围"

所以这里有一个小的工作代码:

var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
      protections[i].addEditor('theEmailYouWantEnabled@email.com');      
    }