假设图片放在D:\a文件夹,命名方式:001.jpg、002.jpg、... 400.jpg
假设excel文档放在D:\b文件夹,命名方式:1.xls、2.xls、... 200.xls
插入图片到excel文档sheet1的最下方,大小800x600,自己调- @set @n=0;/* & echo off & setlocal enabledelayedexpansion
- set "picPath=D:\a"
- set "xlsPath=D:\b"
- pushd "!picPath!\"
- (for /l %%a in (1001 2 1400) do (
- set /a "n=(%%a-999)/2",n1=%%a,n2=%%a+1
- if exist !n1:~1!.jpg if exist !n2:~1!.jpg (
- md !n!
- move !n1:~1!.jpg !n!\ >nul
- move !n2:~1!.jpg !n!\ >nul
- if exist "!xlsPath!\!n!.xls" (
- echo,!xlsPath!\!n!.xls*!picPath!\!n!\!n1:~1!.jpg
- )
- )
- ))>$ 2>nul
- cscript -nologo -e:jscript "%~0"<$
- del $ & pause & exit/b & rem */
-
- ar = WScript.StdIn.ReadAll().split("\r\n");
- oExcel = new ActiveXObject("Excel.Application");
- for (i=0; i<ar.length-1; i++) {
- oBook = oExcel.WorkBooks.Open(ar[i].split("*")[0]);
- oExcel.WorkSheets(1).Activate;
- row = oExcel.ActiveSheet.UsedRange.Rows.Count + 1;
- oExcel.Visible = false;
- oPic = oExcel.ActiveSheet.Pictures.Insert(ar[i].split("*")[1]);
- oPic.ShapeRange.Width = 800;
- oPic.ShapeRange.Height = 600;
- oPic.ShapeRange.Top = oExcel.Cells(row, 1).Top + 5;
- oBook.Save(); oBook.Close();
- oPic = null; oBook = null
- }
- oExcel.Quit(); oExcel = null
复制代码
|