gpt4 book ai didi

google-apps-script - 将一个谷歌驱动器文件夹中的所有照片插入谷歌表格?

转载 作者:行者123 更新时间:2023-12-04 07:18:02 25 4
gpt4 key购买 nike

我不是一个编码员,只是聪明到可以稍微修改代码。但我希望有人可以帮助我。我希望将 google 文件夹中的所有图像上传到带有脚本的电子表格中。我需要根据单元格更改文件夹名称,因此我可以将单元格的名称更改为不同的文件夹运行脚本,脚本将从文件夹中导入所有照片。有些文件夹可能有 5 张照片,其他文件夹可能有 25 张照片。我已经能够弄清楚,但前提是我引用了实际照片,而不仅仅是引用了文件夹的名称并将其全部导入。提前感谢任何和所有帮助。

最佳答案

function insertImages() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const nameF = 'Folder'; // Sheet Name of the sheet containing the Folder Name
const rangeF = 'A1'; // Cell containing the Folder Name
const nameT = 'Target'; // Sheet Name of the sheet to insert images
let row = 2; // Starting row to insert
const col = 1; // Column to insert

const sheet = ss.getSheetByName(nameT);
const folderName = ss.getSheetByName(nameF).getRange(rangeF).getValue();
const folders = DriveApp.getFoldersByName(folderName);
while (folders.hasNext()) {
const folder = folders.next();
const files = folder.getFiles();
while (files.hasNext()) {
const file = files.next();
sheet.insertImage(file.getBlob(), col, row++);
}
}
}

关于google-apps-script - 将一个谷歌驱动器文件夹中的所有照片插入谷歌表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68675321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com