您可以尝试这个示例脚本
function downloadFilesFromFormResponses() {
// Replace these placeholders with your actual values
const SHEET_NAME = "Sheet1"; // Name of the spreadsheet containing URLs
const URL_COLUMN = 1; // Column number (1-based) containing image/PDF URLs
const DOWNLOAD_FOLDER_ID = "YOUR_DOWNLOAD_FOLDER_ID"; // ID of the destination folder
// Get the spreadsheet and the URL column
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
const urlColumn = sheet.getRange(1, URL_COLUMN, sheet.getLastRow());
const urls = urlColumn.getValues();
// Loop through each URL
for (const url of urls) {
const fileUrl = url[0]; // Assuming only one URL per cell (adjust if needed)
// Check if it's an image or PDF URL (modify as needed)
if (fileUrl.endsWith(".jpg") || fileUrl.endsWith(".png") || fileUrl.endsWith(".pdf")) {
const filename = fileUrl.split("/").pop(); // Extract filename from URL
const destinationFile = DriveApp.getFolderById(DOWNLOAD_FOLDER_ID).createFile(filename, UrlFetchApp.fetch(fileUrl).getBlob());
Logger.log("Downloaded file: " + filename);
} else {
Logger.log("Skipping non-image/PDF URL: " + fileUrl);
}
}
}
授予脚本“管理文件”权限时要小心。它允许脚本创建和修改您的云端硬盘中的文件。在运行脚本之前,请确保您了解安全隐患。