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

GASを使ってスプレッドシートの値読み込みと表示

0
Last updated at Posted at 2022-07-28

スプレッドシートを読み込んで、値を出力する例、メモ書きです。
なんだかんだ、excel,powerpointとはなかなか離れられないものです。
で、会社としてはスプレッドシートを導入してるんですね。
JIRAなりのチケットで自動化はしたいところだけど、スプレッドシートを捨てることはなかなかできないんすよね。
だから、スプレッドシートをあれこれするGASっていうのは自動化する時に知っておいた方が良さそうなので、その事始め。

google spreasheetの読み込みと値表示

// スプレッドシートの読み込み
function loadSpreadSheet(url) {
  // nullか空文字か判定
  if (!url) {
    return null;
  }

  // spreadIDを取り出し
  var spredId = url.replaceAll("https://docs.google.com/spreadsheets/d/", '');
  Logger.log("id : " + spredId);

  // IDからスプレッドシートを開く
  return SpreadsheetApp.openById(spredId);
}

function main() {
  var spreadsheet = loadSpreadSheet('https://docs.google.com/spreadsheets/d/あなたのシートのID')
  if (null) {
    return
  }

  // シート1の名称と、スプレッドシートのシートを読み込み
  var sheet = spreadsheet.getSheetByName('シート1');
  var range = sheet.getRange("B2");//セルB2を取得
  Logger.log("B2:" + range.getValue());
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?