2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GASのお勉強!~カスタムメニュー作成、図形タップアクション、メール作成etc~

Last updated at Posted at 2019-12-01

はじめに

ちょっとあってお勉強中です。
自分の中で基本的なことがまとまったので記事にしてみました!
色々できるようになるには小さなことからコツコツと!:hatching_chick:

なんとなく理解された方、下の方に必要だろうリンク置いてあります!ドキュメントにすぐ飛べるようのやつです。:shamrock::seedling::deciduous_tree:

参考URLは被ったりしています!
参考URLは必要なところに記述しています!

:hatched_chick:普通のカスタムメニューの作成

参考:https://developers.google.com/apps-script/guides/menus
参考:https://developers.google.com/apps-script/reference/base/menu

スクリーンショット 2019-12-01 22.53.21.png
sample.gs
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('メニュー')
      .addItem('アイテム', 'menuItem1')
      .addToUi();
}

function menuItem1() {
  SpreadsheetApp.getUi()
     .alert('テキスト');
}

:sun_with_face:onOpen…開いた時に実行される関数
:sunny:addItem(caption, functionName)->Menu…メニューにアイテムを追加
:sunny:addToUi()…メニューをおく
:airplane:menuItem1…アラート表示

:hatched_chick:図形タップアクション

参考:https://developers.google.com/apps-script/guides/menus

sample1.gif

・タップしたい時の関数を作成

sample.gs
function showMessageBox1() {
  Browser.msgBox('You clicked it!');
}

・スプレッドシートに図形を配置
・図形右クリックタップで図形の上の方になんかでるのでそれをタップ。
スクリーンショット 2019-12-01 23.36.31.png
・[スクリプト割り当て]タップで出てきたとこに『showMessageBox1』と入力して保存
・図形タップで処理が実行される

:hatched_chick:関数使用(自作)

参考:https://developers.google.com/apps-script/guides/sheets/functions

・使用したい関数の作成

sample.gs
function DOUBLE(input) {
  return input * 2;
}

・使用するセルに
=DOUBLE(A7)
ように記入、クリック! A7のデータ変えると自動的に変わる!
スクリーンショット 2019-12-02 0.05.20.png

ちなみに、他の方が作った関数なども使用できます。
・アドオン→アドオン取得 でストアへ
・お気に入りをインストール
・インストールすると先ほどのところに項目追加されるので使っていく。
スクリーンショット 2019-12-02 0.20.44.png

:hatched_chick:翻訳(日本語→英語)

参考:https://developers.google.com/apps-script/reference/language/
キーワード:Apps Scriptサービス

sample.gs
function LANGUAGECHANGE(text){
  var english = LanguageApp.translate(text, 'ja', 'en');
  return english;
}
スクリーンショット 2019-12-02 0.54.51.png

:hatched_chick:通常のリクエストのレスポンスをテキストで変換

参考URL:https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

sample.gs
function URLTEXTGET(text){
  var response = UrlFetchApp.fetch(text);
  return response.getContentText();
}
スクリーンショット 2019-12-02 1.16.11.png

※返されるテキスト多すぎるとエラーになります

:hatched_chick:メール送信(普通)

スクリプト実行や図形押した時に実行などで使用してみました!

参考:https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)

sample.gs
function SENDMAIL(){
  GmailApp.sendEmail("*********@gmail.com", "ここにタイトル", "ここに本文");
}
スクリーンショット 2019-12-02 1.38.01.png

:hatched_chick:HTMLのメール送信

参考:https://developers.google.com/apps-script/reference/gmail/gmail-app#advanced-parameters_1

っと言ってもオプションとして指定してあげればいいみたいです!

sample.gs
function SENDMAIL(){
  GmailApp.sendEmail("*****@gmail.com", "ここにタイトル", "ここに本文", {htmlBody:"<h1>こんにちは</h1><p>今日も張り切って行こう!</p>"});
}
スクリーンショット 2019-12-02 1.52.02.png

:hatched_chick:CSVのインポート

参考:https://support.google.com/docs/answer/3093335

=IMPORTDATA("http://www.census.gov/2010census/csv/pop_change.csv")
スクリーンショット 2019-12-04 4.12.33.png

:hatched_chick::hatched_chick:そのほかメモ

用意されている関数

var sheet = SpreadsheetApp.getActiveSheet();
var d1 = sheet.getRange('D1');
d1.setFormula('=SUM(B1, C1)');

GASで使うときはこのように使うみたいです。
参考:https://qiita.com/nyantera/items/fdf1170a964ffaac0dc8

Appsスクリプトサービス
スクリーンショット 2019-12-02 0.59.52.png
スプレッドシートの範囲アクセス
このアプリは確認されていませんのエラー対策
ハンズオン的なものはここら辺から

:hatched_chick::hatched_chick::hatched_chick:さいごに

基本的なことがなんとなくわかったので一安心です!:older_man_tone1:

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?