简体   繁体   English

为Google表格创建自定义功能

[英]Create a custom function for google sheets

I know it's possible to create a function in google sheets via the script editor, I used to be able to do it, now I'm struggling. 我知道可以通过脚本编辑器在Google表格中创建一个函数,我曾经能够做到这一点,现在我很挣扎。
These functions should be accessible through a cell, and be able to use a cell. 这些功能应该可以通过单元访问,并且能够使用单元。
How do I create a function, and how do I use it? 如何创建函数,以及如何使用它?

It's all described quite extensively in the docs: 在文档中对此进行了详尽的描述:

https://developers.google.com/apps-script/guides/sheets/functions https://developers.google.com/apps-script/guides/sheets/functions

To write a custom function: 编写自定义函数:

function DOUBLE(input) {
  return input * 2;
}
  1. Create or open a spreadsheet in Google Sheets. 在Google表格中创建或打开电子表格。
  2. Select the menu item Tools > Script editor. 选择菜单项“工具”>“脚本编辑器”。 If you are presented with a welcome screen, click Blank Project on the left to start a new project. 如果出现欢迎屏幕,请单击左侧的空白项目以启动新项目。
  3. Delete any code in the script editor. 在脚本编辑器中删除任何代码。 For the DOUBLE function above, simply copy and paste the code into the script editor. 对于上面的DOUBLE函数,只需将代码复制并粘贴到脚本编辑器中即可。
  4. Select the menu item File > Save. 选择菜单项文件>保存。 Give the script project a name and click OK. 为脚本项目命名,然后单击“确定”。
  5. All done! 全部做完! Now you can use the custom function. 现在,您可以使用自定义功能。

Using a custom function: 使用自定义函数:

  1. Click the cell where you want to use the function. 单击要使用该功能的单元格。
  2. Type an equals sign (=) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter. 键入等号(=),后跟函数名称和任何输入值(例如= DOUBLE(A1)),然后按Enter。
  3. The cell will momentarily display Loading..., then return the result. 单元格将暂时显示“正在加载...”,然后返回结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM