2
2

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(GoogleAppScript)でimportrangeする方法

Posted at

はじめに

筆者は 大学生限定 プログラミングコミュニティ 『GeekSalon』で活動している者です!

スプレッドシートでimportrangeをしたいがアクセス権がなくてできない...

みなさんはこのような経験をしたことないでしょうか?
importrangeをしたがアクセス権を許可しないといけない
スクリーンショット 2022-07-16 14.34.50.png
アクセス権を許可のボタンを押すと、下の写真のように一生くるくる状態でお手上げ...
スクリーンショット 2022-07-16 14.34.56.png
仕事でどうしてもデータの分析をする必要があり、悩みに悩んだ末...筆者はある方法を閃いたのです!

GAS (GoogleAppScript) でimportrangeしちゃおう!


function importrange() {

var copy_ss = SpreadsheetApp.openById("copyしたいスプレッドシートのURL");
var copy_Sheet = copy_ss.getSheetByName('copyしたいスプレッドシートのシート名');
var copy_Data = copy_Sheet.getDataRange().getValues();

var arr =[]
for (let i = 1; i < copy_Data.length; i++) {
  var area         = copy_Data[i][1]  
  var name         = copy_Data[i][4]  
  var university   = copy_Data[i][5]  
  var date         = copy_Data[i][12]  
  var channel      = copy_Data[i][8]
  var asign        = copy_Data[i][11]

  if (area == '東京' && (channel === "ref" || channel === "tel")) {
    arr.push([date,name,university,asign,channel])
  }
}

var target_ss =SpreadsheetApp.getActiveSpreadsheet();
var target_sheet = target_ss.getSheetByName('ペーストしたいスプレッドシートのシート名');

target_sheet.getRange(2, 1, arr.length, arr[0].length).setValues(arr); 

}

最後に

いかがでしたでしょうか?
不具合等ありましたらご連絡ください!
詳細の解説はまた時間がある時にやろうと思います!今回はとりあえずコピペで使えるところまで!
それではご覧いただきありがとうございました!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?