|
|
发表于 2025-8-24 15:54:48
|
显示全部楼层
本帖最后由 czjt1234 于 2025-8-24 19:39 编辑
vbs- Option Explicit
- Dim oFSO, oWshShell, oShell, oExcel, oWorksheet, temp, s, n, i
- Const zipFolder = "." '当前路径,可自定义
- Const jpgFile = "西红柿.jpg"
- Const ExcelFile = "1.xlsx" '要求文件已存在
- Const Width = 30 '图片的宽
- Const Height = 30 '图片的高
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oWshShell = CreateObject("WScript.Shell")
- Set oShell = CreateObject("Shell.Application")
- Set oExcel = CreateObject("Excel.Application")
- s = oFSO.GetParentFolderName(WScript.ScriptFullname)
- oWshShell.CurrentDirectory = s
- i = oFSO.GetAbsolutePathName(zipFolder)
- s = oFSO.GetAbsolutePathName(ExcelFile)
- Set oWorksheet = oExcel.Workbooks.Open(s).Sheets(1)
- oWorksheet.Columns("B").ColumnWidth = Width
- s = oWshShell.ExpandEnvironmentStrings("%temp%")
- oWshShell.CurrentDirectory = s
- temp = s & oFSO.GetTempName()
- s = ""
- Call EnumZIP(i)
- n = 1
- For Each i In Split(Left(s, Len(s) - 2), vbCrLf)
- oFSO.CreateFolder temp
- oShell.NameSpace(temp).CopyHere oShell.NameSpace(i).Items
- s = ""
- Call EnumJPG(temp)
- If s <> "" Then Call toExcel(s, oFSO.GetBaseName(i))
- oFSO.DeleteFolder temp
- Next
- oExcel.Visible = True
- Sub toExcel(ByVal jpg, ByVal i)
- Dim oPicture
- oWorksheet.Rows(n).RowHeight = Height
- Set oPicture = oWorksheet.Pictures.Insert(jpg)
- oPicture.Top = oWorksheet.Range("B" & n).Top
- oPicture.Left = oWorksheet.Range("B" & n).Left
- oPicture.Width = Width
- oPicture.Height = Height
- oWorksheet.Range("A" & n) = i
- n = n + 1
- End Sub
- Sub EnumZIP(ByVal folderPath)
- Dim oFile, oFolder
- On Error Resume Next
- For Each oFile In oFSO.GetFolder(folderPath).Files
- If LCase(oFSO.GetExtensionName(oFile.Path)) = "zip" Then
- s = s & oFile.Path & vbCrLf
- End If
- Next
- For Each oFolder In oFSO.GetFolder(folderPath).SubFolders
- Call EnumZIP(oFolder.Path)
- Next
- End Sub
- Sub EnumJPG(ByVal folderPath)
- Dim oFile, oFolder
- For Each oFile In oFSO.GetFolder(folderPath).Files
- If LCase(oFile.Name) = LCase(jpgFile) Then
- s = oFile.Path
- End If
- Next
- For Each oFolder In oFSO.GetFolder(folderPath).SubFolders
- Call EnumJPG(oFolder.Path)
- Next
- End Sub
复制代码 只支持 .zip 文件,如果有 .rar 文件需要改用 winrar.exe 或 7z.exe 解压 |
|