繁体   English   中英

Google 表格:如何将图像标题自动填充到单元格列中(不是图像)?

[英]Google Sheets: How to auto populate image titles into a cell column (Not Images)?

我有大约。 我需要将 100,000 个图片标题插入谷歌表格的“A”列。 有没有办法相应地自动将这些填充到单元格中? 每张“照片”都是带有标题的扫描,而不是将每个标题复制并粘贴到我想运行脚本来完成此操作的单元格。 我知道有办法在 Excell 中实现自动化,但由于文件共享的便利性,谷歌表格在这方面处于领先地位。

不让我链接图片,因为我的代表太低了。 照片示例的链接:

https://cdn.extendoffice.com/images/stories/doc-excel/get-picture-name-from-a-folder/doc-list-picture-name-1.png

请注意,我会将任务分成几个部分(一次 1,000 张图像),而不是一次解决所有问题。

下面的脚本适用于 Excell(在另一个站点上作为与该程序有关的相同问题的解决方案提供)列出了整个字符串。 作为最终结果,我希望它只列出图片名称(也没有文件类型,即 .jpg、.png 等)

https://cdn.extendoffice.com/images/stories/doc-excel/get-picture-name-from-a-folder/doc-list-picture-name-13.png

图片名称到Excel()

Dim I As Long
Dim xRg As Range
Dim xAddress As String
Dim xFileName As String
Dim xFileDlg As FileDialog
Dim xFileDlgItem As Variant
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select a cell to place name list:", "Kutools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xRg = xRg(1)
xRg.Value = "Picture Name"
With xRg.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
End With
xRg.EntireColumn.AutoFit
Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
I = 1
If xFileDlg.Show = -1 Then
    xFileDlgItem = xFileDlg.SelectedItems.Item(1)
    xFileName = Dir(xFileDlgItem & "\")
    Do While xFileName <> ""
        If InStr(1, xFileName, ".jpg") + InStr(1, xFileName, ".png") + InStr(1, xFileName, ".img") + InStr(1, xFileName, ".ioc") + InStr(1, xFileName, ".bmp") > 0 Then
            xRg.Offset(I).Value = xFileDlgItem & "\" & xFileName
            I = I + 1
        End If
        xFileName = Dir
    Loop
End If
Application.ScreenUpdating = True

结束子

我认为最简单的方法就是使用 Google Drive Uploader 并将它们全部上传到一个文件夹中。 然后使用文件夹 id 和类似这样的脚本,您可以将它们插入到电子表格中,并且可能不止一个电子表格。

function loadImagesFromFolder() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const fldr=DriveApp.getFolderById('1d7AcmlPU73AsYRLmxorjBlIdmFYj7DRP');//getting the folder from the id
  const files=fldr.getFilesByType(MimeType.JPEG);
  let iA=[];
  //getting all of the file ids into an array
  while(files.hasNext()) {
    const file=files.next();
    const blob=file.getBlob();
    iA.push({name:file.getName(),blob:blob});
  }
  //I sorted them by an number in their name but you may not wish to do that
  iA.sort(function(a,b){
    let vA=Number(a.name.slice(3,4));
    let vB=Number(b.name.slice(3,4));
    return vA-vB;
  });
  //this loaded them into a spreadsheet.  You can also adjust the height and width at the same time
  iA.forEach(function(img,i){
    let row=sh.getLastRow()+1;
    sh.insertImage(img.blob,2, row);
    sh.getRange(row,1).setValue(img.name);
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM