
仕上がりは以下のようになりますが

以下のように、「Path & 画像」の形式で並べたものが欲しい時がちょくちょくあります。

手作業で並び替えたりPathを貼るのは大変なので、自動でやってくれるプログラムを作成しました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job> | |
<script> | |
main=function(){ | |
arg = WScript.Arguments | |
len = arg.length | |
if(!len){return WScript.Echo('画像ファイルをドロップしてください')} | |
excel = new ActiveXObject('Excel.Application') | |
excel.Visible = true | |
bk = excel.Workbooks.Add() | |
sh = bk.Sheets(1) | |
arr = [] | |
for(i=0;i<len;i++){ arr[i] = arg(i) } | |
arr.sort() | |
行 = 1 | |
for(i=0; i<len ;i++){ | |
sh.Cells(行 ,1).Value = path = arr[i] | |
switch('excel2010以降'){ | |
case 'excel2007以前': | |
sh.Cells(行+1,1).Select() | |
application.ActiveSheet.Pictures.Insert(path).Select | |
break | |
case 'excel2010以降': | |
// http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1387042318 | |
// excel2010からPictures.Insertはリンク貼り付けに仕様変更された。 | |
// 埋め込みで使いたい場合の方が多いのでShapes.AddPictureに変更する。 | |
rng = sh.Cells(行+1, 1) | |
obj = sh.Shapes.AddPicture(path, msoFalse=0, msoTrue=-1, rng.Left, rng.Top, 0, 0) | |
obj.ScaleHeight(1, msoTrue) | |
obj.ScaleWidth (1, msoTrue) | |
obj.Select() | |
break | |
} | |
画像高さ = excel.Selection.ShapeRange.Height | |
行高さ = 0 | |
行 = 行 + 1 | |
while(画像高さ > 行高さ){ | |
行高さ += sh.Cells.Rows(行).RowHeight | |
行++ | |
} | |
} | |
} | |
main() | |
</script> | |
</job> |
0 件のコメント:
コメントを投稿