问题描述
我喜欢将Google表格与应用程序脚本一起使用,但是在线脚本ide很麻烦(滞后等),并且没有桌面ide的许多便利.希望Google能够在某个时候创造出桌面理念.有人知道制作Google应用脚本的痛苦程度较小吗?是否有支持远程更新或发布Google脚本的好方法?
I like to use google sheets with app script, but the online script ide is a hassle(lags...etc) and does not have many of the conveniences of a desktop ide. Hopefully, Google will make a desktop ide at some point. Does anybody know of a less painful way of making Google app scripts? Are there any good ides that support remote update or publishing a Google script?
推荐答案
我使用Visual Studio代码在PC上编辑Google Application Scripts项目.
I use Visual Studio Code to edit my Google Application Scripts projects on my PC.
但是,我不是使用"clasp"推送它,而是将生成的代码复制并粘贴到在线Google脚本编辑器中.这是我在PC上设置开发环境的步骤.
However rather than copy and paste the code produced into the online Google script editor, I push it using 'clasp'. Here are the steps I did to set up my dev environment on my PC.
clasp login
打开一个浏览器窗口,您可以在其中选择clasp对其进行身份验证的Google帐户.您还将为clasp提供许多权限,这些权限允许它(除其他外)将google app脚本部署到您的google帐户.
opens up a browser window where you choose your google account that clasp will authenticate itself as. You will also give clasp a number of permissions which allow it (amongst other things) to deploy google app scripts to your google account.
打开脚本中的第三方支持:( https://script.google.com/home/usersettings ),并将Google Application Script API设置为开".
Turn on 3rd party support in scripts : (https://script.google.com/home/usersettings) and set Google Application Script API to "On".
clasp clone <script-id>
将您的脚本项目克隆到当前目录.如果您的项目中只有默认脚本(Code.gs
),这会将Code.js
和appsscript.json
克隆到当前目录.克隆后,.gs
脚本将重命名为.js
. appsscript.json
是项目清单.
clones your script project to the current directory. If you only have the default script (Code.gs
) in your project this will clone Code.js
and appsscript.json
to your current directory. .gs
scripts are renamed to .js
when cloned. appsscript.json
is the project manifest.
要获取脚本项目ID,请打开脚本编辑器,转到文件->项目属性->信息,然后复制在其中找到的脚本ID".
To get the script project id, open the script editor, go to File->Project properties->Info and copy the 'Script ID' you find in there.
在当前目录中创建一个git repo来跟踪脚本项目代码修订.
Create a git repo in your current directory to track script project code revisions.
npm i @types/google-apps-script
安装Google Application Script库,该库使Visual Studio Code能够自动完成Google Application Script类和方法.在与克隆脚本项目相同的目录中执行此操作.
installs the Google Application Script libraries which enable Visual Studio Code to autocomplete Google Application Script classes and methods. Do this in the same directory as you cloned your script project.
在Visual Studio Code中编辑脚本项目.
Edit the script project in Visual Studio Code.
clasp push
将脚本项目推送到script.google.com,以测试更改.
pushes your script project to script.google.com to allow you to test your changes.
记录调试信息
此设置没有为您提供的一种使用调试器调试应用程序脚本的方法.
Logging debug info
What this setup doesn't give you is a way to use a debugger to debug your application script.
不过,您可以将调试信息记录到脚本主页的我的执行"部分: https://script.google.com/home/executions
However you can log debug information to the 'My Executions' section of your scripts home page: https://script.google.com/home/executions
请注意,这仅适用于您从触发器/自定义菜单调用的脚本函数( https ://developers.google.com/apps-script/guides/menus ).它不适用于自定义功能.因此,您尝试通过从Google表格公式调用的Google表格自定义功能尝试进行的任何日志记录都不会最终显示在我的执行"日志中.
Note that this only works from script functions that you call from triggers/custom menus (https://developers.google.com/apps-script/guides/menus). It does not work for custom functions. So any logging you attempt from a google sheets custom function invoked from a google sheets formula will not end up in the My Execution logs.
要在我的执行"中查看日志,必须使用控制台类( https://developers.google.com/apps-script/reference/base/console ).例如:
For logging to be viewable in the 'My Executions' it must be logged using the console class (https://developers.google.com/apps-script/reference/base/console). For example:
console.log("Some useful debug info");
这篇关于Google App脚本桌面IDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!