我在下面有這個電子表格,我希望將整個列鎖定在作業表中,但與今天日期(2022 年 11 月 10 日)匹配的列除外。然后第二天它將鎖定 E 列,11/11/2022 列(F)將被解鎖,依此類推。我想指定可以編輯這些鎖定列的用戶。
這是我的單子。

uj5u.com熱心網友回復:
取消保護今日專欄:
function unprotectTodaysColumn() {
const ss = SpreadsheetApp.getActive();
const sh1 = ss.getSheetByName('Sheet0');
let protection = sh1.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if (protection) { protection.remove(); }
const ds = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yy");
const col = sh1.getRange(1, 1, 1, sh1.getLastColumn()).getDisplayValues().flat().indexOf(ds) 1;
const rg = sh1.getRange(1, col, sh1.getLastRow());
let p = sh1.protect();
p.setUnprotectedRanges([rg])
}
保護
uj5u.com熱心網友回復:
嘗試:
function unprotectToday() {
// Protect whole sheet, then remove all other users from the list of editors.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); //Change sheet name
var protection = sheet.protect();
//Gets the date today and finds its column in the sheet to unprotect
var today = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yy");
var col = sheet.createTextFinder(today).findNext().getColumn();
var unprotect = sheet.getRange(1,col, sheet.getLastRow());
protection.setUnprotectedRanges([unprotect]);
// Ensure the current user is an editor before removing others. Otherwise, if the user's edit
// permission comes from a group, the script throws an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.removeEditors(protection.getEditors());
protection.addEditors([me,"[email protected]","[email protected]"]); //Add users who can edit
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
解釋:
它的作用是保護整張紙。然后它獲取當前日期并在作業表中找到要取消保護的列。在腳本的最后一部分,您還可以添加用戶以允許編輯受保護的范圍。
更多細節在這里: 類保護
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/531670.html
標籤:谷歌应用脚本谷歌表格
