Created
June 2, 2018 00:35
-
-
Save UskeS/dc8e49bdefebc4f438b3386eb100e571 to your computer and use it in GitHub Desktop.
別のスプレッドシートからデータを抽出する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getOtherSheetsValue() { | |
var myObj = {}; | |
//現在のスプレッドシート情報 | |
myObj.doc = SpreadsheetApp.getActiveSpreadsheet(); | |
myObj.sheet = myObj.doc.getSheetByName("シート1"); | |
myObj.range = myObj.sheet.getDataRange(); | |
myObj.values = myObj.range.getValues(); | |
//IDを記述したセルからコンテンツを取得 | |
var tgID = [ | |
myObj.values[0][0], //A1 | |
//myObj.values[0][1], //B1 | |
//myObj.values[0][2] //C1 | |
]; | |
//現在のシートの任意のセルに、ほかのシートから抽出した情報をセットする | |
//@param {array} address 書き込むセル範囲 | |
var setAnotherSheetValue = function (address){ | |
for(var i=0; i<tgID.length; i++){ | |
var tgSS = SpreadsheetApp.openById(tgID[i]); | |
var values = tgSS.getSheetByName("シート1").getRange("B1:B5").getValues(); | |
myObj.sheet.getRange(address[i]).setValues(values); | |
//Logger.log(values); | |
} | |
} | |
setAnotherSheetValue(["A2:A6"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment