用WSH批量修改当前文件夹中所有ppt的链接

来源:互联网 发布:mysql数据库设计教程 编辑:程序博客网 时间:2024/05/17 23:02
将下面的内容保存为app.js
var app = WScript.CreateObject("PowerPoint.Application");app.Visible = true;var fso = WScript.CreateObject("scripting.filesystemobject");var logfile = fso.CreateTextFile("log.txt",  true);var orginAddr,newAddr,arr,filePathvar folder = fso.GetFolder(".");var e = new Enumerator(folder.files);outer:for (; !e.atEnd(); e.moveNext()){    var file = e.item();if(file.Path.indexOf(".ppt") > 0){app.Presentations.open(file.Path,false);app.Activate();for(var i = 1; i <= app.ActivePresentation.Slides.Count; i++){if(!app.ActivePresentation.Slides.Item(i).Hyperlinks)continue;for(var j = 1; j <= app.ActivePresentation.Slides.Item(i).Hyperlinks.Count; j++){orginAddr = app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address;if(orginAddr.indexOf("html") > 0){if(orginAddr.indexOf("/") > 0){arr = orginAddr.split("/");}else{arr = orginAddr.split("\\");}newAddr = "../../" + arr[arr.length - 1];app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address = newAddr ;//记录失效链接if(!fso.FileExists(newAddr)){logfile.WriteLine(file.Name + "\t幻灯片:" +i + ","+ j +" \t" + app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address);}}}}app.ActivePresentation.save();app.ActivePresentation.close();} } logfile.close();
在命令行中运行wscript /x app.js进行调试