VBS脚本插入excel图片
2013-11-23 21:47
477 查看
--VBS脚本插入excel图片
-------------------------2013/11/23
根据第一列的值,需找对应的图片,然后插入的指定的列中,图片根据列的长宽信息决定图片大小。
代码1图片正常状态,不旋转
Dim fso Wscript.StdOut.WriteLine "*********************************************** " Wscript.StdOut.WriteLine "* AUTO INSERT WIN BOTTLE PICTURE * " Wscript.StdOut.WriteLine "* FOR VICKY * " Wscript.StdOut.WriteLine "* version 1.0 2013/11/23 * " Wscript.StdOut.WriteLine "*********************************************** " Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "Please Input which Colunm that you want to insert the pictures ? " excelname=inputbox("Please Input the dirction and file name of the excel you want to process:") no=cdbl(inputbox("Please Input which Colunm that you want to insert the pictures:")) Set fso=CreateObject("Scripting.FileSystemObject") Set xlapp = CreateObject("Excel.Application") Set xlbook = Nothing Set xlsheet = Nothing Set xlbook = xlapp.Workbooks.Open(excelname) Set xlsheet = xlbook.Worksheets(1) intRow = 2 '''''''''''''''''''''''如果不想从第二行开始插入,可以修改参数intRow Do Until xlsheet.Cells(intRow,1).Value = "" bottle_no=xlsheet.Cells(intRow,1).Value xlapp.Visible = False xlsheet.Cells(intRow,no).Select Tpic = "d:\"&bottle_no&".jpg" '''''''''''''''''''在这里修改图片的文件夹路径 If fso.fileExists(Tpic) Then set MyPic = xlsheet.Pictures.Insert(Tpic) MyPic.ShapeRange.Width=xlsheet.Cells(intRow,no+1).Left-xlsheet.Cells(intRow,no).Left-4 MyPic.ShapeRange.Height=xlsheet.Cells(intRow+1,no).Top-xlsheet.Cells(intRow,no).Top-4 MyPic.ShapeRange.Left=xlsheet.Cells(intRow,no).Left+((xlsheet.Cells(intRow,no+1).Left-xlsheet.Cells(intRow,no).Left-MyPic.ShapeRange.Width)/2) MyPic.ShapeRange.Top=xlsheet.Cells(intRow,no).Top+2 End If intRow = intRow + 1 Loop xlbook.Save() xlbook.Close() xlapp.Quit Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "Pictures Inserting finished, press any key to exit !!!" Wscript.StdIn.ReadLine
设置图片旋转为横向:
Dim fso Wscript.StdOut.WriteLine "*********************************************** " Wscript.StdOut.WriteLine "* AUTO INSERT WIN BOTTLE PICTURE * " Wscript.StdOut.WriteLine "* FOR VICKY * " Wscript.StdOut.WriteLine "* version 1.0 2013/11/23 * " Wscript.StdOut.WriteLine "*********************************************** " Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "Please Input which Colunm that you want to insert the pictures ? " excelname=inputbox("Please Input the dirction and file name of the excel you want to process:") no=cdbl(inputbox("Please Input which Colunm that you want to insert the pictures:")) Set fso=CreateObject("Scripting.FileSystemObject") Set xlapp = CreateObject("Excel.Application") Set xlbook = Nothing Set xlsheet = Nothing Set xlbook = xlapp.Workbooks.Open(excelname) Set xlsheet = xlbook.Worksheets(1) intRow = 2 '''''''''''''''''''''''如果不想从第二行开始插入,可以修改参数intRow Do Until xlsheet.Cells(intRow,1).Value = "" bottle_no=xlsheet.Cells(intRow,1).Value xlapp.Visible = False xlsheet.Cells(intRow,no).Select Tpic = "d:\"&bottle_no&".jpg" '''''''''''''''''''在这里修改图片的文件夹路径 If fso.fileExists(Tpic) Then set MyPic = xlsheet.Pictures.Insert(Tpic) MyPic.ShapeRange.IncrementRotation 270 MyPic.ShapeRange.Height=xlsheet.Cells(intRow,no+1).Left-xlsheet.Cells(intRow,no).Left-4 MyPic.ShapeRange.Width=xlsheet.Cells(intRow+1,no).Top-xlsheet.Cells(intRow,no).Top-4 MyPic.ShapeRange.Left=xlsheet.Cells(intRow,no).Left+((xlsheet.Cells(intRow,no+1).Left-xlsheet.Cells(intRow,no).Left-MyPic.ShapeRange.Width)/2) MyPic.ShapeRange.Top=xlsheet.Cells(intRow,no).Top-((MyPic.ShapeRange.Height-xlsheet.Cells(intRow+1,no).Top+xlsheet.Cells(intRow,no).Top)/2) End If intRow = intRow + 1 Loop xlbook.Save() xlbook.Close() xlapp.Quit Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "Pictures Inserting finished, press any key to exit !!!" Wscript.StdIn.ReadLine
相关信息:
console中输入数字:no = cdbl(Wscript.StdIn.ReadLine)
选择excel单元格另一种方法:xlsheet.Range("E4").Select
相关文章推荐
- delphi 操作Excel插入图片
- NPOI导出excel,插入图片
- java POI实现向Excel中插入图片
- Excel VBA 插入指定图片到单元格并只适应大小
- c#向Excel中插入图片
- java POI实现向Excel中插入图片
- Java操作Excel(读、写、搜索关键字、插入图片)
- java POI实现向Excel中插入图片
- 打开Excel文件并插入图片
- java POI实现向Excel中插入图片
- Excel 2007 插入图片问题解决
- asp.net两种方式在模板excel中插入图片:npoi和c# com组件
- Python向Excel中插入图片的简单实现方法
- java excel 实例 jxl ,插入图片,指定格式文字
- C#向Excel报表中插入图片的2种方法【转】
- java : poi 3.10 实现向Excel中插入图片
- C#向Excel报表中插入图片的2种方法
- node.js向EXCEL插入图片
- NPOI向Excel文件插入图片
- 向EXCEL中插入图片测试