从 google 张应用脚本创建文档
Creating document from google sheets app script
我正在尝试使用来自 sheet 的 google 应用程序脚本创建文档。我有以下功能
function createDoc() {
DocumentApp.create('TEST_DOCUMENT');
}
但是当我 运行 它时,我得到了错误
Exception: You do not have permission to call DocumentApp.create. Required permissions: https://www.googleapis.com/auth/documents (linje 26).
在我的 google 应用程序脚本中 appscript.json
我添加了
"oauthScopes": [
"https://www.googleapis.com/auth/documents"
],
获取必要的权限。但我仍然遇到同样的错误。有人知道为什么吗?
编辑:
我的 createDoc() 函数(在底部)
我怎么称呼 createDoc() function
错误信息
我的appscript.json
来自 Custom Function it is not possible to use functions that require authorization. As explained in the documentation:
Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data. Consequently, they can only call services that do not have access to personal data.
作为解决方法,我建议您将函数添加到 Custom Menu:
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Custom Menu')
.addItem('Create new Doc', 'createDoc')
.addToUi()
}
function createDoc(){
DocumentApp.create(`My new Doc - ${new Date().toLocaleDateString()}`)
}
我正在尝试使用来自 sheet 的 google 应用程序脚本创建文档。我有以下功能
function createDoc() {
DocumentApp.create('TEST_DOCUMENT');
}
但是当我 运行 它时,我得到了错误
Exception: You do not have permission to call DocumentApp.create. Required permissions: https://www.googleapis.com/auth/documents (linje 26).
在我的 google 应用程序脚本中 appscript.json
我添加了
"oauthScopes": [
"https://www.googleapis.com/auth/documents"
],
获取必要的权限。但我仍然遇到同样的错误。有人知道为什么吗?
编辑:
我的 createDoc() 函数(在底部)
我怎么称呼 createDoc() function
错误信息
我的appscript.json
来自 Custom Function it is not possible to use functions that require authorization. As explained in the documentation:
Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data. Consequently, they can only call services that do not have access to personal data.
作为解决方法,我建议您将函数添加到 Custom Menu:
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Custom Menu')
.addItem('Create new Doc', 'createDoc')
.addToUi()
}
function createDoc(){
DocumentApp.create(`My new Doc - ${new Date().toLocaleDateString()}`)
}