Using Google Apps Script Libraries

后端 未结 3 795
一向
一向 2021-01-13 19:05

I have read all Google documentation on managing and creating libraries, yet I still do not know if they are an appropriate option for the problem I am trying to solve.

3条回答
  •  既然无缘
    2021-01-13 19:20

    Sorry if I am repeating other answers, but I would like to sum up and add something:

    You can access your library functions as follows:

    From the app using the library you go to the Resources/Libraries. You can see the library name under "Identifier". On the same line where you can select Development mode.

    Library name found in resources

    Now in your library you have for example a function

        function onOpen(e)
       {
         Browser.msgBox("HELLO!"); 
       }
    

    In the spreadsheet app you wish to access it you use the library name found in the resources, for example "testlibrary"

    function onOpen(e)
    {
      testlibrary.onOpen(e);
    }
    

    Now if you have development mode on, the modifications to functions in the library update automatically to your application (spreadsheet) as long as the user using the application has edit access in your library script.

    If anyone using your spreadsheet has a restricted access to your library script (meaning only view access) or development selection is off in the application, you have to go to the application's script, Resources/Libraries and select the most recent version of your library to be used in the app everytime you update the library and save a new version of it.

    Still, especially if you are using mostly only the onOpen function , I would recommend using the library rather than copy-pasting the function to the script of each spreadsheet, as it is easier to track which scripts are up to date and it is easier to avoid errors and differences between the scripts.

    Even in the more restricted case, if you update function in library - as long as you are already calling it in the app - all you have to do is select the new version of the library used.

    I hope I had anything to give in this conversation and my language was appropriate, this was my first answer..

提交回复
热议问题