简体   繁体   中英

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. 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.

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 )

Note I will be breaking the the task into sections (1,000 images at a time), and not tackling it all at once.

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. As an end result I would like it to list ONLY the pic name (also without the file type ie .jpg, .png, etc.)

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

Sub PictureNametoExcel()

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. 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.

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);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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