Gists
This is a sample script for dynamically retrieving the keys and values from struct property using golang.
Sample script: Go Playground
package main
import (
"fmt"
"reflect"
)
func main() {
s := struct {
key1 string
key2 string
key3 string
}{"value1", "value2", "value3"}
r := reflect.ValueOf(&s).Elem()
rt := r.Type()
for i := 0; i < rt.NumField(); i++ {
field := rt.Field(i)
rv := reflect.ValueOf(&s)
value := reflect.Indirect(rv).FieldByName(field.Name)
fmt.Println(field.Name, value.
Gists
This is a sample script for sorting a slice using Golang. Recently, I had a situation for sorting the coordinates of cells of Spreadsheet. As a test case, it thinks of the situation that the randomized cells are sorted. I think that this can be also used for a table except for Spreadsheet.
Sample slice: The sample slice is as follows.
ar := []struct {
row int
col int
value string
}{
{0, 0, "A1"},
{0, 1, "B1"},
{0, 2, "C1"},
{1, 0, "A2"},
{1, 1, "B2"},
{1, 3, "D2"},
{2, 0, "A3"},
{2, 2, "C3"},
} When each element of above slice is put to a Spreadsheet, it becomes as follows.
Overview GetEditType is a GAS library for retrieving the edit types of the OnEdit event trigger of Spreadsheet using Google Apps Script (GAS).
Description In the case that the OnEdit event trigger (simple and installable triggers) is used at Spreadsheet, when users manually edited the cell of Spreadsheet, the trigger is fired. At this time, there is the case that I want to know the edit type. For example, I would like to know about the following edit types.
Gists
This is a sample script for fixing a value putting by a custom function of Spreadsheet using Google Apps Script. When a custom function is used, the value retrieved by the custom function of Spreadsheet is automatically updated by recalculating. So in the case that the value retrieved by the custom function is changed by the time, the value is also changed by automatically updating. In this sample script, I would like to introduce a method for fixing such values.
Gists
This is a sample script for retrieving the values with and without duplicating from JSON object using Google Apps Script. Also this can be used by Javascript.
Sample script var obj = [ { key1: "value1a", key2: "value1b" }, { key1: "value2a", key2: "value2b" }, { key1: "value5a", key2: "value5b" }, { key1: "value3a", key2: "value3b" }, { key1: "value1a", key2: "value1b" }, { key1: "value4a", key2: "value4b" }, { key1: "value5a", key2: "value5b" }, { key1: "value3a", key2: "value3b" } ]; var res = obj.