1
0

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 1 year has passed since last update.

【GAS】便利な関数をまとめたい

Last updated at Posted at 2022-04-30

下記のようなスクリプト.gsを用意しておくと便利。

general.js
// ━━━━━━━━━━━━━━━
// シート定義
// ━━━━━━━━━━━━━━━
var ss = SpreadsheetApp.openById('シートID');
var paramSh = ss.getSheetByName('シート名');

// ━━━━━━━━━━━━━━━
// シート列定義
// ━━━━━━━━━━━━━━━
var titleCol = 1;

// ━━━━━━━━━━━━━━━
// 共通関数
// ━━━━━━━━━━━━━━━
function logger(message) {
  var logSh = ss.getSheetByName('log');
  var date = new Date();
  var lastrow = logSh.getMaxRows()

  logSh.getRange(lastrow + 1, 1).setValue(date);
  logSh.getRange(lastrow + 1, 2).setValue(message);
}

function getLastrow(sh, col) {
  return sh.getRange(sh.getMaxRows(), col).
    getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
}

function getLastcol(sh, row) {
  return sh.getRange(row, sh.getMaxColumns()).
    getNextDataCell(SpreadsheetApp.Direction.PREVIOUS).getColumn();
}

function convUnixtime(jsttime) {
  var unixtime = Date.parse(jsttime)/1000;
  var unixtime_str = unixtime.toFixed();
  var unixtime_int = parseInt(unixtime_str);

  var year = jsttime.getFullYear();
  if (year === 1899) {
    return unixtime_int + 2209194000;
  } else {
    return unixtime_int;
  }
}

function convJsttime(unixtime) {
  return Utilities.formatDate(new Date( unixtime * 1000 ), "JST", "yyyy/MM/dd HH:mm:ss");
}
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?