注意:我的問題沒有通過基于另一個單元格值的保護/取消保護范圍來回答 我的問題詢問了一個范圍,只選擇了部分行,而不是該問題中的整個行。我已經廣泛搜索了該網站,但沒有任何東西可以回答我的問題。
請先正確閱讀我的查詢,然后再將其鏈接到無法回答的其他內容。
問題
我創建了一個共享的測驗 Google 表格作業簿 ( TestWBook ) 來說明我正在嘗試做的事情。“傳出”表是我需要應用限制的地方;它用于存盤訂單資料。
整個“傳出”表 (A1:AS),除了范圍 A2:M882,當前受到保護,因此只有所有者和其他兩個編輯者可以對其進行更改(我們稱他們為 [email protected] 和 [email protected] )。
其他編輯在 A2:M882 中輸入資料以指定新的訂單要求(這就是為什么這個范圍開始時不受保護的原因)。
現在,只要在 O 列中輸入日期(發送日期) (或者如果該單元格不是空白的,則兩者都可以)。
我不想在每次腳本運行時保護整個單行,因為我不想最終得到數百個受保護的范圍。
我希望將保護動態應用于從 A2 到 M(active_row) 的范圍,以便有效地在每次在 O 列中輸入日期/值時更新一個受保護的范圍。
過去兩天我一直在查看腳本,但找不到指定此動態范圍的方法(抱歉,我可以調整腳本但不能從頭開始撰寫它們!)
任何人都可以幫忙嗎?
uj5u.com熱心網友回復:
嘗試
function onEdit(event) {
var sh = event.source.getActiveSheet();
var rng = event.source.getActiveRange();
if (sh.getName() != 'Outgoing') return;
if (rng.getColumn() != 15) return;
// save the protection parameters
var p1 = sh.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
// delete actual protection
let protection = sh.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if (protection) { if (protection.canEdit()) { protection.remove(); } }
// rebuild protection
var p2 = sh.protect();
p2.setDescription(p1.getDescription());
p2.setWarningOnly(p1.isWarningOnly());
if (!p1.isWarningOnly()) {
p2.removeEditors(p2.getEditors());
p2.addEditors(p1.getEditors());
}
// define new uprotected area
p2.setUnprotectedRanges([sh.getRange('A' rng.getRow() ':M882')]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489491.html
