画像URLから画像ファイルを一括生成する方法【業務効率化】【GAS】
0
シートに
URL、ファイル名、拡張子、フォルダIDを作成します。
下記スクリプトを記述します。
function download() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const rows = sheet.getLastRow()-1;
const datas = sheet.getRange(2,1,rows,4).getValues();
datas.forEach(function(data){
const url = data[0];
const folder = DriveApp.getFolderById(data[3]);
const option = {
method:"get"
}
const response = UrlFetchApp.fetch(url,option);
const blob = response.getBlob();
let newFile = folder.createFile(blob);
newFile.setName(data[1]+data[2]);
});
}
//起動時にメニューを手動項目で追加する
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu("ダウンロードはこちら")
.addItem("ダウンロード", "download")
.addToUi();
}
フォルダIDはGoogleドライブのURLが下記の場合、
https://drive.google.com/drive/u/0/folders/hogehgoe
のhogehoge部分です
0