如何从另一个应用程序引用一个应用程序脚本文件
我的应用程序脚本项目中有多个文件。其中一些是为较大应用提供实用程序功能的库文件。如何将它们导入我的主文件?
例如,在节点中,我将能够导入update-cell-1.gs
和update-cell-2.gs
/code>这样的文件:
// update-cell-1.gs
export default function() {
// code to update cell 1
}
// update-cell-2.gs
export default function() {
// code to udpate cell 2
}
// main.gs
import updateCell1 from "update-cell-1.gs";
import updateCell2 from "update-cell-2.gs";
function main() {
updateCell1();
updateCell2();
}
main();
应用程序脚本中的等效内容是什么?
当我尝试使用模块。Exports时,我会收到此错误:
ReferenceError: module is not defined
当我尝试使用导出默认
时,我会得到此错误:
SyntaxError: Unexpected token 'export'
I have multiple files in my apps script project. Some of them are library files that provide utility functions for a larger app. How can I import them into my main file?
For example, in Node, I would be able to import update-cell-1.gs
and update-cell-2.gs
into my main.gs
file like this:
// update-cell-1.gs
export default function() {
// code to update cell 1
}
// update-cell-2.gs
export default function() {
// code to udpate cell 2
}
// main.gs
import updateCell1 from "update-cell-1.gs";
import updateCell2 from "update-cell-2.gs";
function main() {
updateCell1();
updateCell2();
}
main();
What is the equivalent in apps script?
When I try using module.exports, I get this error:
ReferenceError: module is not defined
When I try using export default
, I get this error:
SyntaxError: Unexpected token 'export'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与< node.js 或JS Web Frameworks,您可以在任何文件中调用任何文件直接无需导出或导入任何内容的同一脚本项目。
Unlike node.js or js web frameworks, You can call any function in any file in the same script project directly without exporting or importing anything.
这是一个脚本,可以支持脚本项目中的所有文件。
您可以选择单独的文件或所有一个JSON文件。您还可以选择要保存的文件。
GS:
HTML:
我想念的一些辅助功能也许让我知道。我一直使用此时间备份我的代码。
典型的后备看起来像这样:
Here's a script that backs up all of the files in a script project.
You can choose either separate files or all one JSON file. You can also select which files that you wish to save.
GS:
html:
There maybe some helper functions that I'm missing let me know. I use this all of the time to backup my code.
A typical back up looks like this: