LoginSignup
0
2

More than 5 years have passed since last update.

Google Spread Sheetのファイル日時を自動で特定のセルに書き込むスクリプト

Posted at

これは何?

Google Spread Sheetのファイル更新日をスプレッドシート上のセルに自動で書き込むスクリプトの紹介。

スクリプトの追加方法

  1. [Tools] > [Script editor] を選択。
    Screen Shot 2019-02-25 at 9.58.03.png

  2. 表示されるエディタに以下のコードを貼り付ける
    表示場所、文字列の色を変えたい場合は以下の2つの変数を変更する。
    target_cel: 表示するセルを指定
    cel_color: 表示する文字列の色を指定

function onEdit(e) {
  insertLastUpdated()
}
function insertLastUpdated() {
  var target_cel = 'E1'
  var cel_color = 'black'
  var updated_date = Utilities.formatDate(new Date(), 'JST', 'yyyy/MM/dd HH:mm:ss')
  var user_name = Session.getActiveUser().getEmail()
  var new_title = '更新日:' + updated_date
  if(user_name != "") new_title += ' by ' + user_name
  new_title = '(' + new_title + ')'
  SpreadsheetApp.getActiveSheet()
   .getRange(target_cel)
   .setValue(new_title)
   .setFontColor(cel_color)
}
  1. 名前をつけて保存をして、実行権限を付与する 再生ボタン(以下の画像の赤丸)をクリックすると、
  • ファイル名の決定を促される
  • 実行権限の付与の許可を求められる

のでファイル名を決定し、実行権限の許可を与えてください。
Screen Shot 2019-02-25 at 10.01.44.png

以上で、target_celに指定したセルに、変更があった時に変更日時が自動で挿入されるようになります。

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