google-apps-script - Google 表格:如何将图像标题自动填充到单元格列中(不是图像)?
问题描述
我有大约。我需要将 100,000 个图片标题插入谷歌表格的“A”列。有没有办法相应地自动将这些填充到单元格中?每张“照片”都是带有标题的扫描,而不是将每个标题复制并粘贴到我想运行脚本来完成此操作的单元格。我知道有办法在 Excell 中实现自动化,但由于文件共享的便利性,谷歌表格在这方面处于领先地位。
不让我链接图片,因为我的代表太低了。照片示例的链接:
请注意,我会将任务分成几个部分(一次 1,000 张图像),而不是一次解决所有问题。
下面的脚本适用于 Excell(在另一个站点上作为与该程序有关的相同问题的解决方案提供)列出了整个字符串。作为最终结果,我希望它只列出图片名称(也没有文件类型,即 .jpg、.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);
});
}
推荐阅读
- ossec - 在哪里放置 OSSEC 配置 - 监控 crontab
- spring - 如何使用列表创建实体
- mysql - mariadb-test / mysqltest:符号查找错误:mariadb-test:未定义符号:PCRE2regcomp
- java - PSQLException:错误:运算符不存在:bigint = 字符变化
- python - Pandas:查找多次包含特定单词的数据框字符串条目
- android - 如何在底部导航视图后面显示 recylerview 项目
- go - 忽略不在 Golang 路由器中的 swagger 端点
- javascript - select2 占位符不显示 Localization.resx 文件中法语的变音符号
- python - 使用 GridSearchCV 从 sklearn 获取 ValueError
- smartcard - 行驶记录仪智能卡处理 dsrc 消息