根据用户和日期隐藏工作表 [英] Hide sheets based on user and date

查看:43
本文介绍了根据用户和日期隐藏工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google脚本的新手,需要帮助.我有一个装满12张纸的活页夹,一年中的每个月一次.该工作簿与多人共享,我希望指定的只读人员仅查看过去的一个月,当前的月份以及当前月份之后的月份.但是具有写权限的人可以查看和修改整个工作簿.感谢您的所有帮助,对于我的英语不好,我们深表歉意!

I am new to google script and need help. I have a binder with 12 sheets, one for each month of the year. This workbook is shared with several people and I would like the designated read-only people to see only the past month, the current month and the month following the current month. But that people with write rights can see and modify the entire workbook. Thanks for all the help and sorry for my poor English!

推荐答案

答案:

不幸的是,这不可能做到.

Google表格 可以隐藏/显示不同的表格,并且还可以在打开表格时对其进行更改.但是,您遇到的情况有两个问题:

Google Sheets does have the ability to hide/show different sheets, and also has the ability to change these when the Sheet is opened. There are two problems with your situation, however:

  1. 在工作表的开头运行功能的唯一方法是,如果用户打开工作表具有编辑权限;只读是不够的.
  2. 更改适用于整个工作表,而不仅仅是一个用户.

让我们假设以下情况:

您有一个脚本,该脚本检查打开文件的人的权限状态,并为他们隐藏除上个月,当月和下个月以外的所有工作表.像这样:

You have a script which checks the permission status of a person that opens the file, and hides all sheets for them except the past, current and following month. Something like this:

function permissionChanging() :
    user = userThatOpenedTheFile;

    if userThatOpenedTheFile.Permission = read-only:
        sheets.hide(all-sheets-except-past-current-and-following)
    else if userThatOpenedTheFile.Permission = write:
        sheets.show(all)

现在让我们考虑两个用户:

Now let's conisder two users:

  • 用户A,对工作表具有只读访问权限的用户.
  • 用户B,具有写访问权限的用户.

现在,如果用户A打开文件,因为他们只有只读访问权限,该功能将无法运行-

Now, if User A opens the file, as they only have read-only access, the function won't run - as explained in the script documentation.

对于思想实验,我们现在假设用户A 能够运行该功能:

Let us now assume, for the thought experiment, that User A was able to run the function:

当用户A打开工作表时,该功能将运行,并且除了当前,上个月和下个月外,所有工作表都将被隐藏.他们可以愉快地查看当前表单中的工作表.

When User A opens the Sheet, the function would run, and all Sheets will be hidden except for the current, previous and following months. They can happily look at the sheet in this current form.

现在,用户B在用户A关闭表单之前打开该表单.该脚本再次运行-现在,它取消隐藏所有工作表.由于电子表格存储在云中,因此更改被 应用于表格的所有查看者 -现在,由于用户A 已经工作表打开,更改将传播到他们的视图,现在他们可以看到所有工作表.

Now, User B opens the form, before User A has closed it. The script runs again - now, it unhides all sheets. Because the Spreadsheet is stored in the Cloud, the changes are applied to all viewers of the sheet - so now, as User A already has the sheet open, the changed propagate to their view and now they can see all the Sheets.

我知道这通常是个坏消息,但我希望这对您有帮助!

I know this is generally bad news, but I hope this is helpful to you!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆