【问题标题】:Google sheets get file name from url谷歌表格从 url 获取文件名
【发布时间】:2018-01-04 03:07:05
【问题描述】:

我正在尝试在 google 表格中创建一个函数以从 url 链接获取工作簿名称。

function getFileName(id) {
var file = SpreadsheetApp.openByUrl(id)
var fileName = file.getName();    
return fileName;  
}

我收到消息

“错误 您无权调用 openByUrl"

我试过了

  var file = DriveApp.getFileById(id);

我收到相同类型的消息

“找不到具有给定 ID 的项目,或者您无权访问它。”

【问题讨论】:

    标签: google-apps-script google-sheets custom-function


    【解决方案1】:

    您不能将其用作自定义功能,因为它需要授权。

    Google Documentation

    如果您的自定义函数抛出错误消息You do not have permission to call X service.,则该服务需要用户授权,因此无法在自定义函数中使用。

    要使用上述服务以外的服务,请创建一个运行 Apps 脚本函数的自定义菜单,而不是编写自定义函数。从菜单触发的功能会在必要时请求用户授权,从而可以使用所有 Apps 脚本服务。

    【讨论】:

      猜你喜欢
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 2021-11-01
      相关资源
      最近更新 更多