AppScript ดึงลิงค์ Urlของรูปภาพใน Google Drive

 

function myFunction() {

  var sheet = SpreadsheetApp.getActiveSheet();

  sheet.appendRow(["วันที่", "ชื่อไฟล์", "URL", "ดาวน์โหลด", "รูปภาพ"]); // Added "วันที่" (Datetime) as the first column

  var folder = DriveApp.getFolderById('xxxxx');

  var allFiles = folder.getFiles();

  var i = 0;

  var file;

  

  while (allFiles.hasNext()) {

    file = allFiles.next();

    i++;

    var currentDate = new Date(); // Get the current date and time

    var formattedDate = currentDate.toLocaleString(); // Format the date and time as a string

    var data = [

      formattedDate, // Add the datetime to the first column

      file.getName(),

      file.getUrl(),

      "http://doc.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),

      "=image(\"http://drive.google.com/uc?view&id=" + file.getId() + "\")"

    ];

    sheet.appendRow(data);

  }

}


Previous
Next Post »