簡體   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