[英]Is it possible protect cells and ranges in google sheets after data entry using app script?
[英]Google Sheets Script to allow cells to have data added to them but protect cells from being Deleted
我對人們從谷歌表格中刪除單元格而不是清除內容有疑問。 這些工作表是 static 並且具有條件格式,因此當單元格被刪除時,條件格式變得非常瘋狂。 我需要一個腳本來防止單元格被刪除,但仍允許輸入數據並允許使用我使用的清晰內容腳本清除數據。
我有幾個人在谷歌工作表的工作表的 A 列中輸入數據。 一個人將獲取該數據並在表外執行 function,然后清除內容,以便此過程可以不斷重復。
有很多與單元格相關的條件格式設置,因此用戶可以查看他們輸入的數據是否有效。 如果最終用戶運行此腳本來清除內容:
function ClearCells1() {
var sheet = SpreadsheetApp.getActive().getSheetByName('INT QC');
sheet.getRange('A2:A9660').clearContent();}
我想確保他們無法“刪除”錯誤的單元格,因為這會導致條件格式變得一團糟。
你可以試試下面的腳本
function onEdit(e) {
var user = e.user;
var oldVal = e.oldValue
var newVal = e.value;
var r = e.range;
var rCol = r.getColumn();
var ss = r.getSheet().getSheetName();
var sheet = SpreadsheetApp.getActive().getSheets();
if(user!="user@domain.com" && newVal==undefined && rCol==1 && ss==sheet[0].getName())
// Replace the email address with your own after testing it so that you get access to delete info
{
r.setValue(oldVal);
SpreadsheetApp.getUi().alert("You do not have enough permissions to delete data");
// This generates the alert message, but you can delete if you do not need it.
}
}
任何用戶應該仍然能夠運行您當前的腳本來毫無問題地清除column A
中的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.