powershellでExcel操作+画像ファイルをクリップボード経由でシート貼り付け
ショートカット
cmd.exe /c powershell -noexit \app\scripts\toExcel2.ps1
を作り、そのショートカットへ複数フォルダをドラッグアンドドロップすると、
フォルダ毎別シートになって、ファイル名一覧をシートに書き込む。
拡張子が.DATまたは.csvのものは内容をシートに書き込む。
拡張子が.jpgのものは画像をシートに貼る。
#"\app\scripts\toExcel2.ps1"として保存 #ショートカット #cmd.exe /c powershell -noexit \app\scripts\toExcel2.ps1 #フォルダを複数ドラッグアンドドロップ using namespace System.Drawing; using namespace System.Windows.Forms Add-Type -AssemblyName System.Windows.Forms $excel = New-Object -ComObject Excel.Application $book = $excel.Workbooks.Add() $excel.Visible = "True" $excel.EnableEvents = "False" $excel.DisplayAlerts = "False" function execFolder($fol){ cd $fol $sh = $book.Sheets.Add() $sh.Name = (Get-Item .).BaseName echo $sh.Name $r = $sh.Cells(1,1) $files = dir -name $files.ForEach({ $r.Value = $_ $ext = (Get-Item $_).Extension echo $ext if($ext -eq ".DAT" -or $ext -eq ".csv") { $r.Offset(0,3).Value = cat $_ } $r = $r.Offset(1,0) }) echo $files $files = (dir *.jpg).Fullname $files.ForEach({ echo $r.Address() [Clipboard]::SetImage([Image]::FromFile($_)) [Application]::DoEvents() $sh.Paste($r) $r = $r.Offset(1,0) }) } $args.ForEach({ execFolder($_) }) $excel.EnableEvents = "True" $excel.DisplayAlerts = "True"