简体   繁体   English

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

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

I have approx.我有大约。 100,000 picture titles I need to insert into column "A" on google sheets.我需要将 100,000 个图片标题插入谷歌表格的“A”列。 Is there a way to automatically populate these into the cell(s) accordingly?有没有办法相应地自动将这些填充到单元格中? Each "photo" is a scan with a title, rather then copy and paste each title to the cell I would like to run a script to accomplish this.每张“照片”都是带有标题的扫描,而不是将每个标题复制并粘贴到我想运行脚本来完成此操作的单元格。 I know there is way to automate it in Excell, but because of the ease of file sharing google sheets took the lead on this one.我知道有办法在 Excell 中实现自动化,但由于文件共享的便利性,谷歌表格在这方面处于领先地位。

Wont let me link pictures cause my rep is too low.不让我链接图片,因为我的代表太低了。 Links to photo examples:照片示例的链接:

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

Note I will be breaking the the task into sections (1,000 images at a time), and not tackling it all at once.请注意,我会将任务分成几个部分(一次 1,000 张图像),而不是一次解决所有问题。

The script below is for Excell (Offered as a solution on another site for the same question in regards to that program) lists the entire string.下面的脚本适用于 Excell(在另一个站点上作为与该程序有关的相同问题的解决方案提供)列出了整个字符串。 As an end result I would like it to list ONLY the pic name (also without the file type ie .jpg, .png, etc.)作为最终结果,我希望它只列出图片名称(也没有文件类型,即 .jpg、.png 等)

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

Sub PictureNametoExcel()图片名称到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

End Sub结束子

I think the easiest thing to do is just to use the Google Drive Uploader and upload them all into a folder.我认为最简单的方法就是使用 Google Drive Uploader 并将它们全部上传到一个文件夹中。 Then armed with the folder id and a script something like this one you can insert them into a spread sheet and probably more that one spreadsheet.然后使用文件夹 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.

相关问题 使用Google表格,我如何每小时运行一个脚本并填充列中的每个单元格? - Using Google Sheets, how do I run a script every hour and populate each cell in a column? 当在任何其他单元格中输入特定值时,Google 表格会自动填充单元格中的时间戳 - Google Sheets auto populate timestamp in a cell when a particular value is entered in any other cell Google Sheets Apps Scripts如何在另一个指定列的最后一个非空单元格的同一行中填充特定文本 - Google Sheets Apps Scripts how to populate specific text in the same row of the last non-empty cell in another specified column 使用 Google 表格中的图像填充 Jquery 自动完成 - Populate Jquery Autocomplete With Images From Google Sheets Google表格会在B列发生更改时自动为每一行填充作者 - Google Sheets Auto-Populate the author for each row on change of column B Google 表格图表中的标题 - Titles in Google Sheets Charts 如何在Google表格的列中的每第N行插入一个具有值的单元格 - How to insert a cell with value on every Nth row in a column in Google Sheets 如果谷歌表格中的单元格值为空,如何删除整列 - How to delete entire column if cell value is empty in google sheets 如何根据活动单元格在 Google 表格侧边栏中显示图像 - How to show image in Google Sheets Sidebar based on active cell 如何在 Google 表格中的两个给定日期之间自动填充日期 - How to Auto-Populate Dates Between Two Given Dates in Google Sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM