1

我正在寻找一个可以根据文件名自动在单元格中插入图像的GoogleScript ,步骤如下;

(1) 获取名称(在 A 列中)

(2) 在“图像文件夹”中查找图像文件

(3) 插入固定大小的图片(B列)

我附上表格以供您理解,请帮助我为我生成脚本代码。

GDoc 链接: https ://docs.google.com/spreadsheets/d/1chLNGbmROiPu57wxibNooyreGcnGnS9pyBFM5ZDRTdI/edit#gid=110715797

文件夹链接: https ://drive.google.com/drive/folders/1AV5pTs3l7GGMNH7-C8rixjcWNNTsmbpE?usp=sharing

我使用但不工作的脚本

function listFilesInFolder(folderName) {
    //writes the headers for the spreadsheet
    var sheet = SpreadsheetApp.getActiveSheet();
    sheet.appendRow(["Image"]);
    var folderId = "1AV5pTs3l7GGMNH7-C8rixjcWNNTsmbpE";
    
    var folder = DriveApp.getFolderById(folderId);
    var contents = folder.getFiles();
    
    var cnt = 0;
    var file;
    
    while (contents.hasNext()) {
        var file = contents.next();
        cnt++;
    
        Logger.log(file);
        Logger.log(cnt);
        // writes the various chunks to the spreadsheet- just delete anything you don't want
            data = [
    
                "https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
                file.getDescription(),
                "=image(\"https://docs.google.com/uc?export=download&id=" + file.getId() +"\")",
            ];
    
            sheet.appendRow(data);
    };
};

期待您的快速解决方案和完整的脚本。

提前感谢并感谢天才。

4

0 回答 0