在Google表格中查看基于用户名的特定行 [英] View specific row based on username in Google Sheets

查看:92
本文介绍了在Google表格中查看基于用户名的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个谷歌网站。网站上是电子表格的小工具。我希望小工具根据查看网站的人员的用户名显示电子表格中的特定行。这可能与GAS?



更新:

  function onOpen( ){
var ss = SpreadsheetApp.openById(abcdefg123456789);
var first = ss.getSheetByName(first);
var maxRows = first.getMaxRows();
var email = Session.getActiveUser()。getEmail();

//显示所有行
first.showRows(1,maxRows);

var data = first.getRange('A:A')。getValues();

//遍历所有行
for(var i = 0; i< data.length; i ++){
if(data [i] [0]!= =电子邮件){
first.hideRows(i + 1);
}
if(data [i] [0] ===){
return;
}
}
}

这个代码的问题,或者这可能是GAS的问题,是我无法让它在网站上运行。我将这些代码链接到电子表格,并且在我打开它时隐藏了它应该做的事情(隐藏没有我的电子邮件地址的每一行)。但是,如果我将同一电子表格链接到Google网站,则代码似乎无法运行,并且窗口仍会显示所有其他行。 解决方案

您可以在电子表格和小工具之间使用网络应用代理。在Romain的 Awesome Tables 小工具 =nofollow>行级权限附录。


Let's say I have a google site. On the site is a gadget to a spreadsheet. I want the gadget to show one specific row from the spreadsheet based on the username of the person viewing the site. Is this possible with GAS?

Update:

function onOpen() {
    var ss = SpreadsheetApp.openById("abcdefg123456789");
    var first = ss.getSheetByName("first");
    var maxRows = first.getMaxRows();
    var email = Session.getActiveUser().getEmail();

    //show all the rows
    first.showRows(1, maxRows);

    var data = first.getRange('A:A').getValues();

    //iterate over all rows
    for (var i = 0; i < data.length; i++) {
        if (data[i][0] !== email) {
            first.hideRows(i + 1);
        }
        if (data[i][0] === "") {
            return;
        }
    }
}

The issue with this code, or maybe it's an issue with GAS, is I can't get it to run on sites. I linked this code to a spreadsheet and it does what it's supposed to when I open it (hides every row that doesn't have my email address). However, if I link the same spreadsheet to a google site, the code does not seem to run and the windows will still show all the other rows.

解决方案

You can use a web app proxy between your spreadsheet and the gadget. This technique is demonstrated (along with working code to do what you're looking for) in Romain's Row-level permissions addendum to his Awesome Tables gadget.

这篇关于在Google表格中查看基于用户名的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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