Hiding tabs/sheets in Google Spreadsheet from certain users

别说谁变了你拦得住时间么 提交于 2020-11-29 10:49:20

问题


I am aware of the protect sheet/range function in google spreadsheet but what I want to do is to hide sheets completely from certain users. I have found an answer to this with the code below. I am able to hide certain tabs/sheets to the specified user automatically upon opening the spreadsheet but that doesn't stop them from unhiding the tabs/sheets again. Any recommendations to restrict them from unhiding those tabs?

function onOpen() {
  var adminUsers = ['sample@google.com'];
  var Users = ['sample@gmail.com'];

  if (adminUsers.indexOf(Session.getEffectiveUser().getEmail()) >= 0) {
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SETTINGS').showSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('INSTRUCTION').showSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('EMPLOYEES').showSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('LEAVE').showSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('TEAM DASHBOARD').showSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('EMS').showSheet();
  }

  if (Users.indexOf(Session.getEffectiveUser().getEmail()) >= 0) {
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SETTINGS').hideSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('EMPLOYEES').hideSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('LEAVE').hideSheet();
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('EMS').hideSheet();

    }
}

回答1:


Viewers can't make any change to Google Sheet spreadsheets. In order to prevent that a viewer make a copy to get access to hidden sheets and rows, block the spreadsheet to be printed/copied/downloaded. For details see Stop, limit, or change sharing.

It's worth to note that hiding or showing a sheet will make it effective to all users who are viewing the spreadsheet.



来源:https://stackoverflow.com/questions/50172217/hiding-tabs-sheets-in-google-spreadsheet-from-certain-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!