1
1

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 3 years have passed since last update.

Google App Scriptで自動でログ保存をする

Last updated at Posted at 2019-10-28

スプレッドシート上でシート名'archive'に対し、1行目に最新データを毎日定期更新、その上でその1行目のデータを最終行に追加していく。

function date_update() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('archive');
  var lastrow = sheet.getLastRow();
  sheet.getRange(lastrow-1,6).copyTo(sheet.getRange(lastrow, 6), {contentsOnly:false});
}
 function auto_archives() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('archive');
  var lastrow = sheet.getLastRow() + 1;
  sheet.getRange("A1:E1").copyTo(sheet.getRange(lastrow, 1), {contentsOnly:true});
}

2020/07/13 1プロジェクトでもっと簡単に記載できる方法があったので追記

function auto_archives() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('archive');
  var sheet2 = ss.getSheetByName('data');
  var lastrow = sheet2.getLastRow() + 1;
  sheet.getRange(2,1,1,2).copyTo(sheet2.getRange(lastrow, 1), {contentsOnly:false});
}
1
1
1

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?