[英]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.