Class PageProtection

頁面保護

已淘汰。如果是使用新版 Google 試算表建立的試算表,請改用功能更強大的 Protection 類別。雖然這個類別已淘汰,但仍可用於與舊版 Google 試算表相容。

在舊版 Google 試算表中存取及修改受保護的工作表。

方法傳回類型簡短說明
addUser(email)void將使用者新增至可編輯試算表的使用者清單 (如果試算表受保護)。
getUsers()String[]傳回可編輯此試算表的使用者電子郵件地址清單。
isProtected()Boolean指出工作表是否已啟用工作表保護功能。
removeUser(user)void將使用者從可編輯工作表的使用者清單中移除。
setProtected(protection)void設定工作表的保護狀態。

已淘汰的方法

已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

將使用者新增至可編輯試算表的使用者清單 (如果試算表受保護)。

// Add the "user@example.com" user to the list of users who can edit this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.addUser('user@example.com');
permissions.setProtected(true);
sheet.setSheetProtection(permissions);

參數

名稱類型說明
emailString要新增的使用者電子郵件地址。

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

傳回可編輯此試算表的使用者電子郵件地址清單。

如果工作表保護功能已停用,則此呼叫傳回的值就沒有意義。

回攻員

String[]:可編輯此工作表的使用者電子郵件地址陣列


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

指出工作表是否已啟用工作表保護功能。

// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();

回攻員

Boolean:工作表是否已啟用工作表保護

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

將使用者從可編輯工作表的使用者清單中移除。

// Remove the "user@example.com" user to the list of users who can edit this
// sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.removeUser('user@example.com');
permissions.setProtected(true);
sheet.setSheetProtection(permissions);

參數

名稱類型說明
userString要移除的使用者電子郵件地址。

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

設定工作表的保護狀態。

// Enables sheet protection for  this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);

參數

名稱類型說明
protectionBooleantrue 可啟用工作表保護功能,false 可停用工作表保護功能。

另請參閱