您无权使用copyTo [英] You do not have permission to use copyTo

本文介绍了您无权使用copyTo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将范围从一张纸复制到另一张纸(保留公式).我用copyTo:

I'm trying to copy a range from one sheet to another (whilst preserving the formulas). I wrote a simple script using copyTo:

function copyRangeAcrossSheets(source_sheet,source_range,target_sheet,target_range) {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var source_sheet = spreadsheet.getSheetByName(source_sheet);
  var target_sheet = spreadsheet.getSheetByName(target_sheet);
  var source_range = source_sheet.getRange(source_range);
  var target_range = target_sheet.getRange(target_range);
  source_range.copyTo(target_range);
}

我打电话如下:

=copyRangeAcrossSheets("TEST_source","A1:A3","TEST_target","A1:A3")

我收到以下错误:

您无权调用copyTo

You do not have the permission to call copyTo

我进行了一些挖掘,发现

I did some digging around and found that functions have to use special triggers (installable) in order to modify another file. However here I'm modifying the same file.

问题1:为什么copyTo在这里失败?

Q1: Why is copyTo failing here?

第二季度:如何解决此问题而无需定义可安装的触发器?(我只想在保留公式的同时复制范围)

Q2: How can I workaround the issue without having to define installable triggers? (I just want to copy ranges whilst preserving formulas)

推荐答案

为什么会失败?

您不能修改 other 任何需要通过自定义功能进行授权的文档.原因是您的功能是以匿名用户身份执行的,该用户无法获得编辑您的其他工作表或文档的必要授权.

You cannot modify other any documents that require authorization via a custom function. The reason for this is that your function is executed as an anonymous user, which cannot obtain the necessary authorization to edit other sheets or documents of yours.

参考: https://developers.google.com/apps-脚本/指南/工作表/功能#using_apps_script_services

特定于您的代码段:

电子表格:只读(可以使用大多数get *()方法,但不能设置*()). 无法打开其他电子表格(SpreadsheetApp.openById()或SpreadsheetApp.openByUrl()).

Spreadsheet: Read only (can use most get*() methods, but not set*()). Cannot open other spreadsheets (SpreadsheetApp.openById() or SpreadsheetApp.openByUrl()).

也:

如果您的自定义函数引发错误消息您没有调用X服务的权限." ,则该服务需要用户授权,因此无法在自定义函数中使用.

If your custom function throws the error message "You do not have permission to call X service.", the service requires user authorization and thus cannot be used in a custom function.

您如何解决此问题?

编写通过触发器或手动执行的Apps脚本功能,您可以使用onEditonChange触发器或基于时间的触发器.您甚至可以根据需要在Apps Script IDE中手动运行该功能.这是Apps脚本的预期行为.

Write an Apps Script function that is executed via a trigger or manually, you can use onEdit or onChange triggers, or a time-based trigger. You can even manually run the function in the Apps Script IDE when you need to. This is the intended behavior of Apps Script.

这篇关于您无权使用copyTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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