本帖最后由 went 于 2021-4-26 22:26 编辑
代码保存为test.bat,选择ansi编码
尺寸列表保存为size.txt 单位使用厘米,写两位小数,格式为:宽 高
test.bat和size.txt放到ppt文件夹中双击运行- // & cls & cd /d "%~dp0" & @cscript -E:javascript -Nologo "%~0" &pause&exit
- //判断数组包含
- function ArrayTest(array,item){
- for(var i=0;i<array.length;i++){
- if(array[i] == item)
- return true;
- }
- return false;
- }
- //处理ppt函数
- function handlePPT(path){
- //打开ppt
- ppt.Presentations.Open(path);
- //读取ppt
- var prst = ppt.ActivePresentation;
- for(var i=1;i<=prst.Slides.Count;i++){
- //迭代每一页
- for(var j=1;j<=prst.Slides.Item(i).Shapes.Count;j++){
- //迭代每一张图片
- var pic = prst.Slides.Item(i).Shapes.Item(j);
- var curWH = '' + (pic.Width/28.35).toFixed(2) + ' ' + (pic.Height/28.35).toFixed(2);
- if(ArrayTest(sizeList,curWH)){
- WSH.Echo(curWH);
- WSH.Echo('第' + i + '页删除第' + j + '张图片:' + pic.Name);
- pic.Delete();
- --j;
- WSH.Echo('-------');
- }
- }
- }
- //保存并关闭ppt
- prst.Save();
- prst.Close();
- }
- //读取尺寸列表
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var ofs = fso.OpenTextFile('size.txt',1,false);
- var sizeList = [];
- while(!ofs.AtEndOfLine){
- sizeList.push(ofs.ReadLine());
- }
- ofs.Close();
- WSH.Echo('删除尺寸列表:' + sizeList);
- var ppt = new ActiveXObject('PowerPoint.Application');
- ppt.Visible = true;
- //读取ppt列表
- var fc = new Enumerator(fso.GetFolder('.').files);
- WSH.Echo('---------------------------------');
- while(!fc.atEnd()){
- if(!/\.(pptx|ppt)$/.test(fc.item().name)){
- fc.moveNext();
- continue;
- }
- WSH.Echo('处理: ' + fc.item().path);
- handlePPT(fc.item());
- fc.moveNext();
- WSH.Echo('---------------------------------');
- }
- ppt.Quit();
复制代码
|