LoginSignup
0
0

More than 3 years have passed since last update.

GoogleAppsScript

Last updated at Posted at 2020-10-01

source =

https://developers.google.com/apps-script/guides/services
https://developers.google.com/apps-script/guides/support/best-practices

GoogleAppsScript

  • javascript1.6の上で作られて、js1.7とjs1.8も少しを使っているそうです。「ECMAScript 5 API」のサブセットも入っている
  • シンタックスはjavascriptと似いてる
  • Googleのサービスを様々なオペレーションを自動かにできる。 例:メールを送ったり等。

注意:

Global

  • Spreadsheet上で使いたい場合は必ずSpreadsheetから「ScriptEditor」を開いてください。

Functions

  • renaming a function doesnt apply on elements using that function, you need to refactor manually.( Think about the function name before hand)7
  • .getRange().getValues() return an Array of arrays, even if is just one row or column(x[][])

Date, Time ...

  • GlobalVariable is not the same as normal js ( Use CacheService or something else..)
  • 24:00時の時に「Date.getHours()」は「24」ではなく「0」を返すため、「IF」文を作って「0」の場合は24設定にする。
  • jsでは「Duration」のクラス名がないが「Sheets]ではございます。
  • 「DateTime」を使う際に「Timezone」を気をつけましょう
    • 自分のブラウザーの「Timezone」(jsはIPから計算している)
    • スプレッドシートの「Timezone」(File > Spreadsheet Settings)
    • セールの「Timezone」(値を設定する時に「Timezone」も設定できる:例:2020/10/02 09:00:00 +9:00)

G-Suiteのサービスクラス名

「サービスクラス名」っていうのは
スクリプトでG-suiteのサービスを使うためにそれぞれのクラス名があります。

クラス名はほぼstaticクラスと似たような使い方です。(100%確認不完了)
インスタンスをイニシャライズせずに使うことです。( ClassName.methodName(arguments); )
例:

CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',new Date('July 20, 1969'));

以下にあるものはすべてではありません。

Class ContactsApp
Class CalendarApp
Class DocumentApp
Class DriveApp
Class FormApp
Class GmailApp
Class LanguageApp
Class Maps
Class SpreadsheetApp

SpreadsheetApp

GoogleDriveのSpreadsheetを操作できるクラス名。

Methods

Active spreadsheet

On active sheet

SpreadsheetApp.getActiveSheet();

開いていないsheet

var sheetIWant = 3
SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[sheetIWant];


開いていないSpreadsheet

データしかアクセスできないので、「getActive()」などが使えないです。
「getActive()」って複数がありますがUIと繋がっているため他のシートを読み込みたいときに使えない。

var ss = SpreadsheetApp.openById(SPREADSHEET_ID_GOES_HERE);
var sheets = ss.getSheets();
// the variable sheets is an array of Sheet objects
var sheet1A1 = sheets[0].getRange('A1').getValue();
var sheet2A1 = sheets[1].getRange('A1').getValue();

「SPREADSHEET_ID_GOES_HERE」はURLから貰えます。
例:
image.png

ID = 1bMWXwPNI7v_P6zJHeaRC6G0LbSETj5tMN-9ICUs8Q0s

SlidesApp

NOTE. Google Slides Class

https://developers.google.com/apps-script/reference/slides/slides-app

// Get the current presentation to which this script is bound.
var presentation = SlidesApp.getActivePresentation();

クラス

  • PageElement : controls element in the page
  • SheetsChart : a chart connected to google sheets data

Event Triggers

「イベントトリガー」って、設定したイベントを行なってから設定した自動に関数を実行させる。

例:1分ごとにupdate(){}をする。
設定した日付

Log

AppScriptからブラウザーのCONSOLE.LOGを使えない。
console.log などの表示画面は以下の通り:

https://script.google.com/home/executions

image.png

Google Visualization API Query Language

SheetsをURLでQueryしてHtmlで表示。

https://docs.google.com/spreadsheets/d/1TW_Ylg51v2qjJEmjQxe1y2lCpZ8gZjuNUUX3AQSLXa8

グーグルシートのURLの後ろにつけて

/gviz/tq?

次は出力の設定

tqx=out:html

とシートIDの設定

&gid=1464693090

とクエリの設定

&tq=

クエリを書いて

 select "$value" from "$column_name"

エンコーディングして(グーグルのエンコーディングツール)
image.png

https://developers-dot-devsite-v2-prod.appspot.com/chart/interactive/docs/querylanguage_f900873fea70da5281fcde423564d6bad05d5f672a9ef2dccc2e919fe0d16ce4.frame

最後はクエリをつけます

select%20A%2C%20sum(B)%20group%20by%20A

完了なURL

https://docs.google.com/spreadsheets/d/1TW_Ylg51v2qjJEmjQxe1y2lCpZ8gZjuNUUX3AQSLXa8/gviz/tq?tqx=out:html&&gid=1464693090tq=select%20*%20

https://developers.google.com/chart/interactive/docs/querylanguage
https://acrl.ala.org/techconnect/post/query-a-google-spreadsheet-like-a-database-with-google-visualization-api-query-language/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0