tanaike - Google Apps Script, Gemini API, and Developer Tips

The Thinker

Dynamically Updating Custom Menu of Google Spreadsheet using Google Apps Script

Gists

This is a sample script for dynamically updating the custom menu of Google Spreadsheet using Google Apps Script.

Demo

In this demonstration, when the Spreadsheet is opened, 5 functions added to the custom menu. You can see that when a column is added and deleted, the custom menu is updated.

Issue and workaround for this goal

Unfortunately, in the current stage, when a function is added to the custom menu with addItem method, the argument cannot been able to be used. And when one of functions in the custom menu is run, the information about the function name which was run cannot be retrieved. By this, the goal cannot be directly achieved. So it is required to use the workaround.

GAS Library - GmailToList

Overview

This is a library for exporting all messages of Gmail as a list using Google Apps Script (GAS).

Description

Recently, I have had a situation it had been required to backup all messages in own Gmail. In order to achieve this, I created a simple script. After I created it, I thought that when such situation might occur for other users and the script is published as a library, they might be useful. So I created this library. But I created this for my situation. So if this cannot be used for your environment and an error occurs, I apologize.

Moving File to Specific Folder using Google Apps Script

Gists

These are 3 sample scripts for moving a file to the specific folder in Google Drive using Google Apps Script.

Sample script 1

In this script, only Drive Service is used.

var sourceFileId = "###";
var destinationFolderId = "###";

var file = DriveApp.getFileById(sourceFileId);
DriveApp.getFolderById(destinationFolderId).addFile(file);
file
  .getParents()
  .next()
  .removeFile(file);

Sample script 2

In this script, only Drive API at Advanced Google services. (In this case, it’s Drive API v2.)

var sourceFileId = "###";
var destinationFolderId = "###";

Drive.Files.update({ parents: [{ id: destinationFolderId }] }, sourceFileId);

Sample script 3

In this script, only Drive API v3 is used.

Figma to Google Slides using Google Apps Script

Gists

In this sample script, all pages in the Figma file are retrieved and the retrieved pages are put to new Google Slides as the image.

Usage

1. Retrieve access token

You can see the method for retrieving the access token at here. Although there is also OAuth2 for retrieving the access token, in your situation, I thought that the method for directly generating the access token on the site might be suitable. So in this answer, the generated access token on the site is used. Please retrieve the access token as follows.

Retrieving Values from Sheet Filtered by Slicer in Spreadsheet using Google Apps Script

Gists

Overview

This is a sample script for retrieving values from a sheet filtered by Slicer in Spreadsheet using Google Apps Script.

Description

By the update of Google side at November 6, 2019, Class Slicer was added. And also, for Sheets API, AddSlicerRequest and UpdateSlicerSpecRequest were added. By this, Slicer of Spreadsheet got to be able to be managed with Google Apps Script and other languages.

Here, I would like to introduce the method for retrieving values from a sheet filtered by Slicer in Spreadsheet using Google Apps Script.

Automatic Recalculation of Custom Function on Spreadsheet Part 2

Gists

Description

I have already reported about “Automatic Recalculation of Custom Function on Spreadsheet Part 1” at here. Here, I would like to introduce other workaround for forcibly recalculating the custom functions and built-in functions using Class TextFinder. Class TextFinder has added at April 5, 2019. By this, this workaround can be proposed.

Sample scripts

Pattern 1

If you want to refresh all functions of all sheets in a Spreadsheet, you can use the following script. In this script, when the script is run, all built-in functions and custom functions in the Spreadsheet are refreshed.