spreadsheet

Taking Advantage of TextFinder for Google Spreadsheet

Gists There is Class TextFinder in Spreadsheet service for Google Apps Script. Ref The TextFinder can search and replace the texts in the Spreadsheet using Google Apps Script. There is the method for createTextFinder in Class Spreadsheet, Class Sheet and Class Range. When these methods are used, you can search and replace the texts for all sheets in a Spreadsheet, the specific sheet, and the specific range in the specific sheet.

Putting All Response Values from Google Form to Google Spreadsheet using Google Apps Script

Gists This is a sample script for putting all response values from Google Form to Google Spreadsheet using Google Apps Script. Sample script Please copy and paste the following script to the script editor of Google Spreadsheet and set the variables of formId and sheetName. function myFunction() { const formId = "###"; // Please set the Google Form ID. const sheetName = "Sheet1"; // Please set the sheet name of sheet you want to put the values.

Large Decimal Numbers and Exponential Notation for Google Spreadsheet

Gists In this report, it has investigated the large decimal numbers and the exponential notation for Google Spreadsheet. When the large decimal numbers are put to the Spreadsheet, the Spreadsheet automatically sets the display value using the exponential notation. In this report, the result when the values are retrieved by Spreadsheet service and Sheets API is shown. Sample script At first, please create new Spreadsheet and open the script editor. And please copy and paste the following script.

Compiling Continuous Numbers using Google Apps Script

Gists This is a sample script for compiling the continuous numbers using Google Apps Script. For example, the values of [4, 5, 9, 3, 10, 5, 11, 7, 7, 13, 1] are converted to ["1","3-5","7","9-11","13"]. Sample script const compilingNumbers = (ar) => { const { values } = [...new Set(ar.sort((a, b) => a - b))].reduce( (o, e, i, a) => { if ( o.temp.length == 0 || (o.temp.length > 0 && e == o.

Retrieving List of All Emails of Microsoft Account using Google Apps Script

Gists This is a sample script for retrieving the list of all emails of Microsoft account and putting them to Google Spreadsheet using Google Apps Script. I updated OnedriveApp to v1.2.0 by adding 1 method for retrieving the access token and 7 methods for managing emails of Microsoft account. By this, the emails got to be able to be gotten and sent using Microsoft account using OnedriveApp with Google Apps Script.

Benchmark: Concurrent Writing to Google Spreadsheet using Form

Gists Published: September 15, 2021 Updated: September 17, 2021 From the discussions, added data by changing the wait time of LockService for Web Apps. Kanshi Tanaike Introduction When the users try to write to a Spreadsheet using a form, the developers have to consider the concurrent submission from the form. For example, when multiple users submit the data with the form simultaneously, all data are possibly not to be saved to the Spreadsheet.

Retrieving Hidden Rows and Showing Rows by Filter View on Google Spreadsheet using Google Apps Script

Gists This is a sample script for retrieving the hidden rows and showing rows by the filter view on Google Spreadsheet using Google Apps Script. In the current stage, there are no methods for directly retrieving the hidden rows and showing rows by the filter view in Spreadsheet service (SpreadsheetApp). And, isRowHiddenByFilter of Class Sheet cannot be used for the filter view. But, fortunately, when Sheets API is used, the filter view can be retrieved and created.

Benchmark: Process Costs for Retrieving 1st Empty Cell and 1st Non Empty Cell of Specific Column in Google Spreadsheet using Google Apps Script

Gists Introduction Here, I would like to report the process costs for retrieving the 1st empty cell or 1st non empty cell of the specific column of Google Spreadsheet using Google Apps Script (GAS). For this situations, the following 2 patterns can be considered. Retrieving 1st empty cell of specific column by searching from TOP of sheet Retrieving 1st NON empty cell of specific column by searching from BOTTOM of sheet

Creating Colorful Buttons on Google Spreadsheet using Google Apps Script

Gists This is a sample script for creating the colorful buttons on Google Spreadsheet on Google Apps Script. In order to achieve this, I have been looking for the method for creating the PNG image with the alpha channel using Google Apps Script. Recently, finally, I could find it. By this, the goal of this report got to be able to be achieved by the report of “Creating PNG Image with Alpha Channel using Google Apps Script”.

Copying Protections for Spreadsheet using Google Apps Script

Gists This is a sample script for copying the protections for Spreadsheet using Google Apps Script. When several protections of the sheet protection and the range protection are set to a Google Spreadsheet and the Spreadsheet is copied using the script and the manual copy with the browser, unfortunately, the protections of ranges are not copied. And also, the protections of sheets can be copied. But, the editor emails are not included.

Downloading Active Sheet in Google Spreadsheet as CSV and PDF file by Clicking Button

Gists This is a sample script for downloading the active sheet in Google Spreadsheet to the local PC as a CSV file and a PDF file when a button on the side bar and the dialog is clicked. This is created with Google Apps Script and HTML&Javascript. In this post, the script of the previous post was modified. Sample script Please create new Google Spreadsheet and copy and paste the following scripts to the script editor.

Replacing Multiple Values in Google Spreadsheet with Low Process Cost using Google Apps Script

Gists This is a sample script for replacing the multiple values with various values in Google Spreadsheet with the low process cost using Google Apps Script. In this script, the batchUpdate method of Sheets API is used. So the request can be done by one API call. When Spreadsheet services is used for this situation, the values are retrieved from the sheet and replaced the retrieved values, and then, the updated values are put to the sheet.

Benchmark: Measuring Process Costs for Formulas in Cells on Google Spreadsheet using Google Apps Script

Gists Description When Google Spreadsheet is used, there is the case that the built-in functions and the custom functions in the cells are used. For the functions of Google Apps Script, there is the method for measuring the process cost. Ref But for the built-in functions, it is required to create the script for it. In this report, the script for measuring a function put in a cell has been proposed, and the process cost of the built-in functions has been measured.

Downloading Google Spreadsheet as XLSX and PDF file by Clicking Button

Gists This is a sample script for downloading Google Spreadsheet to the local PC as a XLSX file and a PDF file when a button on the side bar and the dialog is clicked. This is created with Google Apps Script and HTML&Javascript. Sample script Please create new Google Spreadsheet and copy and paste the following scripts to the script editor. And please run openSidebar(). By this, the side bar is opened to the Spreadsheet.

User Runs Script for Range Protected by Owner using Google Apps Script

Gists There is a situation that it wants to make users run a script for the range protected by the owner using Google Apps Script. This is a sample script that an user runs a script for the range protected by the owner using Google Apps Script. Demo This demonstration shows the following situations. Spreadsheet is shared with an user. The cell “A1” is protected by the owner.

Creating Multiple Buttons on Google Spreadsheet using Google Apps Script

Gists This is a sample script for creating the multiple buttons on Google Spreadsheet using Google Apps Script. Recently, I have got several contacts about this. I thought that when this is published, it might be useful for other users. So I published this sample script. Sample script Please copy and paste the following script to the script editor of the container-bound script of Google Spreadsheet. And, please set the variables and run the function createButtons.

Retrieving All Values from All Sheets from URL of 2PACX- of Web Published Google Spreadsheet using Python

Gists This is a sample script for retrieving all values from all sheets from URL of 2PACX- of Web Published Google Spreadsheet using Python. In this post, it supposes that the Google Spreadsheet has already been published for Web. Ref Flow The flow of this method is as follows. Retrieve XLSX data from the URL of web published Google Spreadsheet as BytesIO data. The URL is like https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml. XLSX data is parsed with openpyxl.

Retrieving All Values from All Sheets from URL of 2PACX- of Web Published Google Spreadsheet using Node.js

Gists This is a sample script for retrieving all values from all sheets from URL of 2PACX- of Web Published Google Spreadsheet using Node.js. In this post, it supposes that the Google Spreadsheet has already been published for Web. Ref Before you use this sample script, please install SheetJS js-xlsx. Flow The flow of this method is as follows. Retrieve XLSX data from the URL of web published Google Spreadsheet as the buffer data.

Retrieving All Values from All Sheets from URL of 2PACX- of Web Published Google Spreadsheet using Google Apps Script and Javascript

Gists This is a sample script for retrieving all values from all sheets from URL of 2PACX- of Web Published Google Spreadsheet using Google Apps Script and Javascript. In this post, it supposes that the Google Spreadsheet has already been published for Web. Ref Flow The flow of this method is as follows. From the client side, send the URL of web published Google Spreadsheet to the Web Apps created by Google Apps Script.

Sorting Cells on Google Spreadsheet with Background colors using Google Apps Script

Gists This is a sample script for sorting the cells on Google Spreadsheet with the background colors using Google Apps Script. Unfortunately, in the current stage, it seems that sort(sortSpecObj) of Class Range cannot directly sort by the background colors of cells. But when Sheets API is used, this goal can be achieved. Here, “SortRangeRequest” of the method of “spreadsheets.batchUpdate” in Sheets API is used. Flow The flow of this sample script is as follows.

Setting Alternate Background Colors for Rows in Google Spreadsheet using Google Apps Script

Gists This is a sample script for setting alternate background colors for rows in Google Spreadsheet using Google Apps Script. It has already been known when the conditional formatting rule and custom function are used, this can be simply achieved. Ref In this report, I would like to introduce the method for using Google Apps Script. Sample script In this sample script, the values of column “A” are checked. function myFunction() { const colors = { color1: "#f4cccc", color2: "#d9ead3" }; const sheet = SpreadsheetApp.

Running Specific Function When Specific Sheet is Edited on Google Spreadsheet

Gists This is a sample Google Apps Script for running the specific function when the specific sheet is edited. Sample script Please copy and paste the following script to the container-bound script of Spreadsheet and set sheets object. // When the cells are edited, this function is run by the fire of event trigger. function onEdit(e) { // Please set the sheet name and function as follows. const sheets = { Sheet1: functionForSheet1, // Sheet1 is the sheet name.

Creating Spreadsheet with Custom Header and Footer using Google Apps Script

Gists In order to print and export as PDF file, this is a sample script for converting Spreadsheet to Spreadsheet which has the custom header and footer. In this sample script, DocsServiceApp, which is Google Apps Script library, is used. And, in this case, the Spreadsheet with the custom header and footer is created as new Spreadsheet. Before you use this script, please install DocsServiceApp and enable Drive API at Advanced Google services.

GAS Library - DocsServiceApp

Overview This is a Google Apps Script library for supporting Document service, Docs API, Spreadsheet service, Sheets API, Slides service and Slides API. The aim of this library is to compensate the processes that they services cannot achieve. Description The Google services, which are Document service, Docs API, Spreadsheet service, Sheets API, Slides service and Slides API, are growing now. But, unfortunately, there are still the processes that they cannot done.

Converting Range in Google Spreadsheet as Image using Google Apps Script

Gists This is a sample script for converting a range in Google Spreadsheet as an image data using Google Apps Script. Unfortunately, there are no methods for directly converting the range in Google Spreadsheet as an image data in the built-in functions. So in this case, as a workaround, Charts Service is used. Sample script const range = "B5:D10"; const [header, ...values] = SpreadsheetApp.getActiveSheet() .getRange(range) .getDisplayValues(); const table = Charts.newDataTable(); header.

Switching Buttons for Google Spreadsheet using Google Apps Script

Gists These are the sample scripts for achieving the switching buttons for Google Spreadsheet using Google Apps Script. The management of images using Spreadsheet service is growing now. But, in the current stage, in order to achieve the switching buttons, it needs a little ingenuity. In this report, I would like to introduce 4 kinds of the switching buttons. Pattern 1 In this pattern, the drawing is used as the button.

Using Request Body of String JSON for Google APIs with googleapis of golang

Gists This is a sample script for directly using the request body of the string JSON for Google APIs with googleapis of golang. At googleapis for golang, when Google API is used, it is required to create the request body like this sample script. I have several contacts for creating about such request body. I thought that such script might be a bit difficult for users. I thought that when the string JSON object is directly used for this, it might be useful.

Setting Number Format of Cells on Google Spreadsheet using batchUpdate in Sheets API with golang

Gists This is a sample script for setting the number format of cells on Google Spreadsheet using batchUpdate in Sheets API with golang. In this case, googleapis for golang is used. The script of the authorization can be seen at the official document. Sample script In this script, the number format of the column “A” is changed to yyyy-mm-dd hh:mm:ss. And, please include https://www.googleapis.com/auth/spreadsheets to the scopes. sheetId := 12345678 // Please set the sheet ID which is not Spreadsheet ID.

Adjusting Text Length to Fit in Cell Width on Google Spreadsheet using Google Apps Script

Gists This is a sample script for adjusting the text length to fit in the cell width on Google Spreadsheet using Google Apps Script. In this case, in order to fit to the cell width, the font size is changed. Issue and workaround: Unfortunately, in the current stage, there are no methods for automatically resize the font size for fitting in the cell width in the Spreadsheet service. So in this case, it is required to think of the workaround.

Search Dialog Sample using TextFinder with Google Apps Script

Gists This is a sample script for the search dialog using TextFinder with Google Apps Script. If this sample script could help to indicate the possibility of TextFinder, I'm glad. Demo In this demonstration, the value of test is searched. When "NEXT" is clicked, the next searched value is activated. When "PREVIOUS" is clicked, the previous searched value is activated. The search can be done for all sheets in the Google Spreadsheet.

Workaround: Putting Multiple Hyperlinks to a Cell using Sheets API

Gists This is a current workaround for putting the multiple hyperlinks to a cell using Sheets API. Description Recently, at Spreadsheet service, the multiple hyperlinks got to be able to be put to a cell. Ref In this case, it can be achieved using RichTextValue. On the other hand, at Sheets API, in the current stage, there are no methods for directly putting the multiple hyperlinks to a cell. And also, such methods have not been added.

Updated: Expanding A1Notations using Google Apps Script

Gists This sample script is for expanding a1Notations using Google Apps Script. This was updated from this sample script. Sample script function expandA1Notations_(a1Notations, maxRow, maxColumn) { maxRow = maxRow || "1000"; maxColumn = maxColumn || "Z"; // Ref: https://stackoverflow.com/a/21231012/7108653 const columnToLetter = column => { let temp, letter = ""; while (column > 0) { temp = (column - 1) % 26; letter = String.fromCharCode(temp + 65) + letter; column = (column - temp - 1) / 26; } return letter; }; const letterToColumn = letter => { let column = 0, length = letter.

Retrieving Overwrapped Cells Between 2 Ranges on Google Spreadsheet using Google Apps Script

Gists This is a sample script for retrieving the overwrapped cells between 2 ranges on Google Spreadsheet using Google Apps Script. Please use this with enabling V8. const getOverwrappedRanges_ = (rangeList1, rangeList2) => { if ( rangeList1.toString() != "RangeList" || rangeList2.toString() != "RangeList" ) { throw new Error("Input RangeList object."); } // Ref: https://stackoverflow.com/a/21231012/7108653 const columnToLetter = column => { let temp, letter = ""; while (column > 0) { temp = (column - 1) % 26; letter = String.

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.

Append Values by Inserting Rows using Google Sheets API

Gists In the case appending values to cell by inserting rows, when sheets.spreadsheets.values.append is used, the values are appended to the next empty row of the last row. If you want to append values to between cells with values by inserting row, you can achieve it using sheets.spreadsheets.batchUpdate. When you use this, please use your access token. Endpoint : POST https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###:batchUpdate Request body : In this request body, it appends the data of “sample1, sample2, sample3” to “A1:A3” of the sheetId of “1234567890”.

Automatic Recalculation of Custom Function on Spreadsheet Part 1

Gists In this report, I would like to introduce a workaround for automatically recalculating custom functions on Spreadsheet. 1. Situation The sample situation is below. This is a sample situation for this document. There are 3 sheets with “sheet1”, “sheet2” and “sheet3” of sheet name in a Spreadsheet. Calculate the summation of values of “A1” of each sheet using a custom function. Sample script of the custom function is as follows.

spreadsheets.values.batchUpdate using Golang

Gists Flow : In my sample script, the script was made using the Quickstart. The flow to use this sample script is as follows. For Go Quickstart, please do Step 1 and Step 2. Please put client_secret.json to the same directory with my sample script. Copy and paste my sample script, and create it as new script file. Run the script. When Go to the following link in your browser then type the authorization code: is shown on your terminal, please copy the URL and paste to your browser.