|
因为用到了imagemagick把webp转换为png再插入
所以索性写个批处理- #ANSI编码&cls&powershell -Version 5.1 -NoLogo -NoProfile -Command "gc -Encoding Oem -ReadCount 0 -LiteralPath '%~f0'|out-string|iex"&pause&exit/b
- $xl = New-Object -ComObject Excel.Application
- $wb = $xl.Workbooks.Open((Resolve-Path '.\新建 Microsoft Excel 工作表.xlsx').Path)
- $r = 2
- while ($true) {
- $t = $wb.Sheets(1).Range('A' + $r).Value2
- if ($t -ne $null) {$r++} else {break}
- $f = gci -Recurse | ?{$_.Name -match $t} | select -First 1
- magick $f.Fullname 'tmp.png'
- $p = $wb.Sheets(1).Shapes.AddPicture((Resolve-Path 'tmp.png').Path, 0, -1,
- $wb.Sheets(1).Range('B' + ($r - 1)).Left,
- $wb.Sheets(1).Range('B' + ($r - 1)).Top,
- 100, 120)
- rm tmp.png
- $wb.Sheets(1).Range('B' + ($r - 1)).EntireRow.RowHeight = $p.Height
- }
- $wb.Save()
- $wb.Close()
- $xl.Quit()
复制代码
|
|