Google apps script 谷歌应用程序脚本在一个电子表格中有多个脚本

Google apps script 谷歌应用程序脚本在一个电子表格中有多个脚本,google-apps-script,Google Apps Script,我为谷歌电子表格应用程序开发了几个通用脚本函数。 目前,我将每个功能保存在笔记本电脑上的单个文件中。为了包括他们 在电子表格中,我只知道一种方法 将单个函数文件合并到一个文件中。 然后将合并文件中的数据复制并粘贴到 电子表格的脚本编辑器,替换以前的内容 如果有一种方法(例如使用“项目”)可以 单个函数文件可以保存一次,然后我可以 只需在新脚本中根据需要引用这些函数 我不知道是否有这种可能性。我只看到一个节点 在电子表格内容的树列表中称为“代码” 非常感谢您的帮助。团队刚刚发布了一项新功能:,请查

我为谷歌电子表格应用程序开发了几个通用脚本函数。 目前,我将每个功能保存在笔记本电脑上的单个文件中。为了包括他们 在电子表格中,我只知道一种方法

将单个函数文件合并到一个文件中。 然后将合并文件中的数据复制并粘贴到 电子表格的脚本编辑器,替换以前的内容

如果有一种方法(例如使用“项目”)可以 单个函数文件可以保存一次,然后我可以 只需在新脚本中根据需要引用这些函数

我不知道是否有这种可能性。我只看到一个节点 在电子表格内容的树列表中称为“代码”


非常感谢您的帮助。

团队刚刚发布了一项新功能:,请查看它是否符合您的要求

编辑: 这很简单:选择一个包含要添加到库中的脚本的电子表格,保存脚本的一个版本,将此版本添加到库中,并将提供的密钥复制到某个位置(此密钥也是用于管理库的url的一部分) 在另一个电子表格中,转到“管理库”,添加密钥并保存。 在新脚本中,只需键入库名+dot+CTRL空格(auto-complete),就可以直接使用该库的所有函数。 希望这足够清楚。 参见示例的屏幕帽:Caltosheet是库的名称,它在字母C上以自动完成形式出现)


团队刚刚发布了一项新功能:,请查看它是否符合您的要求

编辑: 这很简单:选择一个包含要添加到库中的脚本的电子表格,保存脚本的一个版本,将此版本添加到库中,并将提供的密钥复制到某个位置(此密钥也是用于管理库的url的一部分) 在另一个电子表格中,转到“管理库”,添加密钥并保存。 在新脚本中,只需键入库名+dot+CTRL空格(auto-complete),就可以直接使用该库的所有函数。 希望这足够清楚。 参见示例的屏幕帽:Caltosheet是库的名称,它在字母C上以自动完成形式出现)


谢谢Serge。我查了一下“图书馆”,这里是我发现的

  • 任何包含一个或多个脚本项目的电子表格文件都可以作为 图书馆。script_项目构成了库定义

  • 电子表格文件可以包含一个或多个脚本项目

  • 脚本函数的界面位于“工具”菜单下 在电子表格文件中。此菜单包含三(3)个相关条目 要创建脚本,请执行以下操作:

  • 脚本库(我尚未浏览此条目)
  • 脚本管理器 A.此条目提供所有项目和功能的列表视图 在每个“项目”中都可以找到。列表按函数名称排序,然后 项目名称。第三栏是“服务”,我目前只看到它 查找“电子表格”的值。我没有研究过其他类型的问题 文档、“站点”和“服务”,以了解还会出现什么。 B在这个显示屏的底部是一个菜单,上面显示了您可以执行的操作 对列表项执行:运行、编辑、新建、关闭。
    -运行:执行突出显示的脚本。 -编辑:打开所选项目/功能的“脚本编辑器”。 这与“工具”菜单上的第三(3)项相同(见下文)。 -新的。在无标题(空)项目上打开“脚本编辑器”。这 与从“工具”中选择“脚本编辑器”选项的操作相同 没有以前保存的脚本时的菜单。 -关闭:这将关闭脚本管理器窗口。这和 按下右上角的“X”按钮
  • 脚本编辑器。 这使您可以访问用于操作的函数: A.库-具有已定义版本号的脚本项目 B项目-一个或多个文件的集合。 C文件-一个或多个JavaScript函数的集合。 D函数-一组可以引用的JavaScript语句 (调用)通过电子表格接口或其他接口 JavaScript函数

     When the Script Editor is accessed from a new spreadsheet, it creates
     a new (untitled) PROJECT. The new project contains one FILE. The name 
     of the initial file is "Code". This is the initial "tree" entry under
     the "untitled project" root in the left column of the editor's screen.
     The contents of the "Code" file is listed in the right column "text_area".
     The text_area is initialized with an empty FUNCTION definition which has
     the name "myFunction".
    
     The text_area provides normal standard text editing functions that you find
     in other script editors (copy, paste, cut; overlay/insert typing text 
     selection replace(with paste) and delete. 
    
     The text_area shows the complete contents of the file. This may be
     one or more "function" definitions. 
    
     The major functions of the editor in managing PROJECTs and FILEs at
     a "higher" level are found under the "File" menu. 
    
     The "File" menu contains the following entries:
    
     1. New - This allows you to insert a new PROJECT into the spreadsheet,
              or a new FILE in the current PROJECT. It also allows you to 
              create other types of documents. But I have not explored these
              options.
     2. Open - This sub-menu provides you with a list of PROJECTS contained
               within the spreadsheet and allows you to switch projects, or
               to access an additional file under a project. 
    
               When a PROJECT is opened, The tree structure lists all of
               the files contained in the project. The names of the files
               are also listed in "tab" above the text_area. You can switch
               between files by either clicking on the tree entry or the 
               "tab" name.  
     3. Revision History - provides you with a list of saved contents of 
               the project. You can back-off changes using this option.
    
     4. Rename - This sub-menu allows you to change the name of a FILE
                 within a PROJECT, or the name of the PROJECT. The object
                 that is renamed is determined by the entry selected in 
                 the "tree" in the left column.
    
     5. Delete - This sub-menu allows you to delete either a FILE within
                 a PROJECT or the entire PROJECT. The object deleted is
                 determined by the high-lighted entry in the tree structure
                 in the left column.
    
     6. Make A Copy - inserts a duplicate copy of the current file selected
                 in the tree structure, and switches access to the copied 
                 file's contents. If the current entry in the tree structure
                 is the PROJECT entry, then this and other sub-functions 
                 which do not apply at the PROJECT level are inactivated
                 (grayed out).
    
     7. Save   - Marks the current contents of the selected file as a
                 restore point, and saves its contents so that it is
                 accessible the next time the editor manipulates this project.
                 You can have unsaved changes in multiple files. This option
                 only saves changes to the currently active file.
    
     8. Save All - This saves the contents of all files that have unsaved
                   changes. The editor places a "red star" in front of the 
                   FILE's name in the "tab" for that file. As each file's
                   changes are saved. the "red star" is removed.
    
    
     9. Manage Versions - This sub-menu allows you to assign a NEW version
                   number to a project. It really does not allow you 
                   to manage the current version definitions. It prompts
                   you for a description (a reason for creating a new version).
    
                   By defining a "version" number you make the PROJECT usable
                   as a library. 
    
    10. Project Properties - This sub-menu provides access to a set of attributes
                   that are associated with the PROJECT object. I have not 
                   explored the use of "User Properties" and "Project Properties"
                   tabs. I expect that they are concerned with saving Key-value
                   pairs (as global variables) across spreadsheet access sessions.
                   But I will explore them later.
    
                   The important attribute on the "INFO" tab (for me) is the
                   "Project Key" attribute. This is the value that you must
                   copy/paste into another spreadsheet file, in order to access
                   the functions contained in this PROJECT without having to 
                   copy the actual function definitions into referencing 
                   spreadsheet file. 
    
     11. Build a user interface - I have not explored this sub-menu.
    
    
     Now once you have assigned a "version" number to a project, that project
     can be used as a "reference" (i.e. LIBRARY) in another spreadsheet file.
    
     Here is how you do this:
        1. Go to the spreadsheet file that contains the PROJECT (i.e.LIBRARY)
           that contains the PROJECT you want to "reference"
        2. Access the "tools" menu to gain access to the project. Use either
           the "Script Manager", or the "Script Editor" options. If your 
           spreadsheet only has one PRJOECT, then the "Script Editor" will
           take you to that PROJECT. Otherwise, use the Script Manger, to
           select the PROJECT. (If you open the Script Editor, and the spreadsheet
           file has more than one PROJECT, it will prompt you to select which
           PROJECT that you want to access.
        3. Go to the "File/Project Properties" sub-menu within the editor and
           select (high-light) the Project Key's attribute's value. and copy
           it to your "clip board" (i.e. CTRL-c). You can then close this
           spreadsheet file.
        4. Open the spreadsheet file that contains the scripts that needs
           to reference the functions from the other PROJECT(LIBRARY). 
        5. Access the PROJECT containing the functions that are to call
           the external functions from the LIBRARY.
        6. In the editor go to the "Resourses/Manger Libraries" sub-menu.
           You will receive a panel with the title "INCLUDED LIBRARIES".
        7. To add the new library reference, paste the copied Project Key
           value into the "Find a Library" field, and press the "SELECT"
           button. 
        8. If you have not made an error, you will set the list of libraries
           updated to include your PROJECT added to the list. 
    
     Each row in the PROJECT (library) list contains 5 entries. Here
     is how they are used.
    
           1. Title - This contains the name of the PROJECT from the other
                      spreadsheet file. This is the name that is associated
                      with the "Prject Key". You can not change this value,
                      within this referencing file. 
           2. Version - This shows which version of the PROJECT resources that
                      you are allowed to access by this definition. The 
                      drop-down list shows you which versions are available
                      and the comment you entered when you created the version.
           3. Identifer - This shows you the qualifier that you are to use
                      within your FUNCTION definitions to uniquely identify
                      which function you are calling.  You are allowed to 
                      change this value even after you have initially defined
                      it. This identifier is similar to a "namespace" qualifier
                      that is found in an XML document. If you change the 
                      qualifier value you must make a similar change to 
                      all code within your functions that reference this 
                      identifier, otherwise an error is thrown at execution
                      time (to the end user) that an undefined identifier has
                      been encountered.
           4. Development Mode - This attribute impacts the execution of the
                      scripts in the current spreadsheet. It tells the spreadhseet
                      engine NOT TO SAVE the compiled image of the target 
                      (referenced) library. This will slow down the execution
                      of your script since the spreadsheet engine will compile
                      your script every time you execute it, and it will also
                      recompile the contents of the LIBRARY each time. You should
                      only use "Development mode" when you are debugging a problem
                      with a library script.
           5. Remove - when clicked removes the "Library definition" from the list
                      of included libraries. 
    
        Library definition changes are automatically saved when you close the
        mangers access panel. At the bottom of the panel are two buttons.
        "SAVE" - allows you to save changes and continue to make Library 
        definitions. CANCEL - causes the manger function to exit. Any 
        changes since the last SAVE are discarded.
    
        To call a Library function in your script is similar to calling
        the "msgBox" method of the "Browser" object. For example to 
        call the msgBox function you include "Browser.msgBox('...')"
        clause.
    
        To call the "doSomething" function in a library (project) for
        which you assigned the "identifier" of "LETS", you would 
        code the clause "LETS.doSomthing(....)". 
    
    
    
    After discovering these "facts", I have come to the following 
    conclusions:
    
        1. The purpose of the spreadsheet file should be to only hold the 
           LIBRARY function definitions.  
    
        2. If you are going to use a PROJECT as a LIBRARY, then you probably
           will want to have multiple PROJECTs in the spreadsheet file that 
           contains the LIBRARY.  The primary PROJECT should hold the 
           function definitions that make up the LIBRARY. A second project
           should be defined that holds testing functions. Only the LIBRARY
           project should be given a version number.
    
        3. The spreadsheet data in general will not be available to the
           scripts that references the LIBRARY. They can be made available
           but not without opening the libraries spreadsheet file as a 
           separate application.
    
        4. I don't know (since I have not tested this), but I assume that
           the PROJECT PROPERTIES and USER PROPERTIES of the library (spreadsheet)
           file are NOT accessible to the library functions when they are called.
           I can see both, views which would allow and prohibit this access.
           For security reasons I would guess that they would not be available.
           (I could be wrong! - and generally I am).
    
        5. I like the idea of using FILES. In fact, I plan to use one file 
           for each function.  From a Object Oriented Programming perspective,
           you will probably want to use a separate file for each Object's
           definition.  You must realize (at this time) the JavaScript language
           does not support "Object Definitions".  The use of FILES as a container
           seems to be the reason for creating the FILE construct. 
    
        6. The FILE object also allows you to limit the scope of view and change
           to functions within the FILE. In this way, you cannot corrupt other 
           functions which are not in the file. 
    
        7. I found a significant impact on execution time when a script is run
           that references one or more Libraries.  My guess is that execution
           performance can be improved over time, with the use of JIT and caching
           facilities.
    
        8. From an end-user's perspective, it would be nice is a "clock" type
           cursor icon would appear to the end user when a script is executing.
           This is very important considering the time it takes to execute code
           that references library functions.
    
        9. For script execution performance reasons, you may anticipate that
           you will have to make the library functions an actual part of your
           spreadsheet file.  Looking ahead to this possibility, I would 
           create dummy (skeleton) functions within my spreadsheet scripts
           which do nothing more that pass the input parameters to the 
           library functions with the proper namespace identifier. Then
           when I have to copy in the library functions I only have to 
           change the dummy functions. I would put these skeleton functions
           into a separate file. I would use one file for each library 
           reference definition. 
    

  • 谢谢,谢尔盖。我查了一下“图书馆”,这里是我发现的

  • 任何包含一个或多个脚本项目的电子表格文件都可以作为 图书馆。script_项目构成了库定义

  • 电子表格文件可以包含一个或多个脚本项目

  • 脚本函数的界面位于“工具”菜单下 在电子表格文件中。此菜单包含三(3)个相关条目 要创建脚本,请执行以下操作:

  • 脚本库(我尚未浏览此条目)
  • 脚本管理器 A.此条目提供所有项目和功能的列表视图 在每个“项目”中都可以找到。列表按函数名称排序,然后 项目名称。第三栏是“服务”,我目前只看到它 查找“电子表格”的值。我没有研究过其他类型的问题 文档、“站点”和“服务”,以了解还会出现什么。 B在这个显示屏的底部是一个菜单,上面显示了您可以执行的操作 对列表项执行:运行、编辑、新建、关闭。
    -运行:执行突出显示的脚本。 -编辑:打开所选项目/功能的“脚本编辑器”。 这与“工具”菜单上的第三(3)项相同(见下文)。 -新的。在无标题(空)项目上打开“脚本编辑器”。这 与从“工具”中选择“脚本编辑器”选项的操作相同 没有以前保存的脚本时的菜单。 -关闭:这将关闭脚本管理器窗口。这和 按下右上角的“X”按钮
  • 脚本编辑器。 这