容器绑定的Google脚本即使在共享容器后也不会执行 [英] Container-Bound Google Script not executing even after the container has been shared

查看:103
本文介绍了容器绑定的Google脚本即使在共享容器后也不会执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个Google表格中编写了一个脚本,当点击一个按钮时,它会复制活动工作表中的数据并将其粘贴到另一个文件中。当登录到任何谷歌帐户脚本运行良好,但当匿名用户单击按钮没有任何反应。根据有关容器绑定脚本的信息,它们的权限镜像容器的权限。我已经确保该容器与匿名用户共享,但脚本仍然不会执行,除非登录。



我做错了什么?代码如下。

$ p $ 函数DataCapture(){


//设置表格

var source_sheet = SpreadsheetApp.getActiveSpreadsheet();
var target = SpreadsheetApp.openById(0AtYhRMASIGlFdGVQWFprMEpOOFRrUGYxTmNGd0dZLVE);
var target_sheet = target.getSheetByName('Data');

//获取目标最后一行
var last_row = target_sheet.getLastRow();

//设置范围
var source_range = source_sheet.getRange(A2:P2);
var target_range = target_sheet.getRange(A+(last_row + 1)+:P+(last_row + 1));
var info_range = source_sheet.getRange(D7:E7);
var dollar_range = source_sheet.getRange(B7:B8);
var approver_range = source_sheet.getRange(D7:F7);

//获取值
var values = source_range.getValues();

//保存到电子表格
target_range.setValues(values);

//清除下一个条目的字段
source_range.clearContent()
info_range.clearContent()
dollar_range.clearContent()
审批者范围。 clearContent()

}


解决方案

该按钮将在用户权限下运行。如果它是匿名的,如果它需要任何api权限(比如阅读电子表格),它就不会运行,因为没有用户。
对于非匿名用户,您需要添加一个菜单项,以触发Google权限对话框(只需执行任何愚蠢的api调用)。用户批准后可以点击图像按钮

I've written a script within one of my google sheets that when a button is clicked it copies data from the active sheet and pastes it into another file. When logged in to any google account the script runs great but when anonymous users click the button nothing happens. According to the information regarding container-bound scripts, their permissions mirror the permissions of the container. I've insured that the container is shared for editing with anonymous users but the script still won't execute unless logged in.

What am I doing wrong? Code below.

function DataCapture() {


    // Set Sheets

    var source_sheet = SpreadsheetApp.getActiveSpreadsheet();
    var target = SpreadsheetApp.openById("0AtYhRMASIGlFdGVQWFprMEpOOFRrUGYxTmNGd0dZLVE");
    var target_sheet = target.getSheetByName('Data');

    // Get target last row
    var last_row = target_sheet.getLastRow();

    // Set Ranges
    var source_range = source_sheet.getRange("A2:P2");
    var target_range = target_sheet.getRange("A"+(last_row+1)+":P"+(last_row+1));
    var info_range = source_sheet.getRange("D7:E7");
    var dollar_range = source_sheet.getRange("B7:B8");
    var approver_range = source_sheet.getRange("D7:F7");

    // Fetch values
    var values = source_range.getValues();

    // Save to spreadsheet
    target_range.setValues(values);

    // Clear the fields for the next entry
    source_range.clearContent()
    info_range.clearContent()
    dollar_range.clearContent()
    approver_range.clearContent()

}

解决方案

The button will run under the users permission. If its anonymous it wont run if it needs any api permission (like reading the spreadsheet) since there is no user. For non anonymous users, you need to add a menu item that will trigger the google permission dialog (just do any dumb api call from it). After the user approves it will be able to click the image button

这篇关于容器绑定的Google脚本即使在共享容器后也不会执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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