Use this Google Workspace Add-on in Google Sheets to instantly import custom functions, built using Apps Script.
- Go to the add-on page
- Click on Admin/individual install
- Open sheets.new
- Name the sheet (this is so the "Untitled Spreadsheet" gets saved to the Google Drive)
- Enable your Google Apps Script API by navigating to this link
- Note: In case you have signed-in using multiple Google accounts in the same browser sessions, ensure that you're enabling the API with the same account in which the add-on has been installed
- [Optional] Refresh the add-on
- Click on any of the function you see from the grid and click to navigate to its page
- Click on the IMPORT button
Once you've imported a function, those would be as easy to use as a built-in function:
- Click the cell where you want to use the function.
- Type an equals sign (
=
) followed by the function name and any input value — for example,=DOUBLE(A1)
— and press Enter. - The cell will momentarily display
Loading...
, then return the result.
In general, we'll follow the "fork-and-pull" Git workflow:
- Fork this repo on GitHub
- Work on your fork
- All the files that you'll need to work with would be in the functions folder
- Make your additions or changes there
- Commit changes to your own branch
- Make sure you merge the latest from "upstream" and resolve conflicts (if any)
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
Use the following as a template when adding a new function —
// @author WorkspaceDevs https://developers.google.com/apps-script/guides/sheets/functions#optimization
/**
* Multiplies the input value by 2.
*
* @param {number} input The value or range of cells to multiply.
* @return {number} The input multiplied by 2.
* @customfunction
*/
function DOUBLE(input) {
return Array.isArray(input) ?
input.map(row => row.map(cell => cell * 2)) :
input * 2;
}
- JSDoc styled comments
- The description of the function needs to go all the way on the top (within JSDoc)
- Function needs to have —
- a clear/defined input
@param
(there can be more than 1 of these) - A single
@return
tag
- a clear/defined input
- JSDoc will need to end with the
@customfunction
tag - Ensure to rigorously test the function in your own Apps Script project
- Have the
@author
tag added at the very first line of the file (if any) - While the function can return a single value, where possible, it would be good to be able to accomodate
Array
input and return too
Refer the general instructions layed out under the Contribute section.
Copyright (c) 2022 Custom Functions
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.