頁面 保護措施
已淘汰。如果是使用新版 Google 試算表建立的試算表,請改用功能更強大的 Protection
類別。雖然這個類別已淘汰,但仍可與舊版 Google 試算表相容。
在舊版 Google 試算表中存取及修改受保護的工作表。
已淘汰的方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
| void | 如果試算表受到保護,可將使用者新增至可編輯試算表的使用者清單。 |
| String[] | 傳回可編輯這份試算表的使用者電子郵件地址清單。 |
| Boolean | 指出工作表是否已啟用工作表保護功能。 |
| void | 從可編輯工作表的使用者清單中移除使用者。 |
| void | 設定工作表的保護狀態。 |
已淘汰的方法
add User(email)
add User(email)
已淘汰。這項函式已淘汰,不應在新指令碼中使用。
如果試算表受到保護,系統會將使用者新增至可編輯試算表的使用者清單。
// Add the "[email protected]" user to the list of users who can edit this sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.addUser('[email protected]'); permissions.setProtected(true); sheet.setSheetProtection(permissions);
參數
名稱 | 類型 | 說明 |
---|---|---|
email | String | 要新增的使用者電子郵件地址。 |
另請參閱
get Users()
get Users()
已淘汰。這項函式已淘汰,不應在新指令碼中使用。
傳回可編輯這份試算表的使用者電子郵件地址清單。
如果停用工作表保護,這項呼叫傳回的值就沒有意義。
回攻員
String[]
:可編輯這份試算表的使用者電子郵件地址陣列。
is Protected()
is Protected()
已淘汰。這項函式已淘汰,不應在新指令碼中使用。
指出工作表是否已啟用工作表保護功能。
// Determine whether or not sheet protection is enabled const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); const isProtected = permissions.isProtected();
回攻員
Boolean
:工作表是否已啟用工作表保護功能。
另請參閱
remove User(user)
remove User(user)
已淘汰。這項函式已淘汰,不應在新指令碼中使用。
從可編輯工作表的使用者清單中移除使用者。
// Remove the "[email protected]" user to the list of users who can edit this // sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.removeUser('[email protected]'); permissions.setProtected(true); sheet.setSheetProtection(permissions);
參數
名稱 | 類型 | 說明 |
---|---|---|
user | String | 要移除的使用者電子郵件地址。 |
另請參閱
set Protected(protection)
set Protected(protection)
已淘汰。這項函式已淘汰,不應在新指令碼中使用。
設定工作表的保護狀態。
// Enables sheet protection for this sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.setProtected(true); sheet.setSheetProtection(permissions);
參數
名稱 | 類型 | 說明 |
---|---|---|
protection | Boolean | true 啟用工作表保護功能,false 停用工作表保護功能。 |