Function from script editor works fine but not from sheets custom function

前端 未结 2 861
广开言路
广开言路 2021-01-17 06:16

I wrote a function that adds an all-day event.

When the function running from script editor it\'s working fine, the all-day event is inserted to the calendar.

相关标签:
2条回答
  • 2021-01-17 06:26

    Answer:

    While it is not possible to run a script which requires authorisation directly from a cell in a Sheet, you can set up the script to run on button click instead.

    More Information & Workaround:

    As a button does not have the same authorisation restrictions as custom functions, you can use them to run code with the scopes you need. To set this up:

    1. Go to the Insert > Drawing menu item and create a shape; any shape will do, this will act as your button.
    2. Press Save and Close to add this to your sheet.
    3. Move the newly-added drawing to where you would like. In the top-right of the drawing, you will see the vertical ellipsis menu (). Click this, and then click Assign script.
    4. In the new window, type whatever the name of your function is, without parentheses (for example myFunction), and press OK.

    I hope this is helpful to you!

    References:

    • Custom Functions in Google Sheets | Apps Script | Google Developers
    0 讨论(0)
  • 2021-01-17 06:26

    That is because you are not allowed to use a custom function to perform actions that require authorization such as adding an event to your calendar.

    From the official documentation:

    Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data.

    However, there are some workarounds that you could try. For example, you can create a custom menu option within your spreadsheet file or a time-driven trigger.

    0 讨论(0)
提交回复
热议问题