一、word篇。
思路:直接利用word.application提供的方法將word轉存為html格式,但是排版會出現錯位現象(暫時定好容器寬度可以解決。偷懶)。
<script type="text/javascript"> function saveword(){ try{ var WordApp=new ActiveXObject("Word.Application"); } catch(e){alert("failed!!");} WordApp.visible=false; try{ var Document=WordApp.Documents.Open("F://test.doc"); alert(WordApp.width); } catch(e){WordApp.Quit();alert(e);} try{ Document.SaveAs("F://website//mytestwebsite//test//test.html",8); } catch(e){WordApp.Quit();alert(e);} Document.close(); WordApp.Quit(); } </script>
二、ppt篇。
思路:依然利用powerpoint.application提供的方法,將ppt以png格式導出到指定臨時文件夾,然后在通過jquery圖片展示插件,進行展示。
<script type="text/javascript"> var num; function pptOpen(file) { try{ var fso = new ActiveXObject("Scripting.FileSystemObject"); } catch(ex){ alert("fso bad!!"); ppt.quit(); } try{ if(!fso.FolderExists("F:\\website\\mytestwebsite\\temps")) { alert("folder not exists"); fso.CreateFolder("F:\\website\\mytestwebsite\\temps"); } } catch(ex){ alert("folder bad!!"); fso.close(); //ppt.quit(); } //fso.close(); try{ var ppt = new ActiveXObject("PowerPoint.Application"); } catch(ex){ alert("create bad!!"); ppt.quit(); } //ppt.visible = true; try{ var pre = ppt.Presentations.open(file,false,false,false); } catch(ex){ alert("open"+file+" bad!!"); ppt.quit(); } num = pre.Slides.Count; //alert(num); try{ pre.Export("F:\\website\\mytestwebsite\\temps","png"); } catch(ex){ alert("Export bad!!"); pre.close(); ppt.quit(); } pre.close(); ppt.quit(); aa(); } function ss(){ $("<div></div>").attr("id","menu").appendTo("#she"); $("<ul></ul>").attr("id","xx").appendTo("#menu"); $("<div></div>").attr("id","con").addClass("con").appendTo("#she"); for(var x=1;x<=num;x++) { $("#xx").append($("<li>"+x+"號</li>").attr({"id":"lii"+x})); $("<div></div>").attr("id","sheet"+x).appendTo("#con"); $("<img></img>").attr("src","temps/幻燈片"+x+".PNG").appendTo("#sheet"+x); } //$("#tab").tabs(); function tabit(ul,css,div){ $(div).children().hide(); $(div).each(function(){ $(this).children().eq(0).show(); }); $(ul).each(function(){ $(this).children().eq(0).addClass(css); }); $(ul).children().hover(function(){ $(this).addClass(css).siblings().removeClass(css); var index = $(ul).children().index(this); $(div).children().eq(index).show().siblings().hide(); }); } tabit("#xx","active","#con"); } function aa() { $("<div></div>").attr("id","menu").appendTo("#she"); $("<button>上一頁</button>").attr("id","prev").appendTo("#menu"); $("<button>下一頁</button>").attr("id","next").appendTo("#menu"); $("<div></div>").attr("id","con").addClass("con").appendTo("#she"); for(var x=1;x<=num;x++) { $("<div></div>").attr("id","sheet"+x).appendTo("#con"); $("<img></img>").attr("src","temps/幻燈片"+x+".PNG").appendTo("#sheet"+x); } function tabit(div){ $(div).children().hide(); $(div).each(function(){ $(this).children().eq(0).show(); }); var index = 0; $("#prev").click(function(){ //var index = 0; $(div).children().eq(--index).fadeIn().siblings().hide(); //index--; if(index==-1) { //alert("第一張"); index=$(div).children().size()-1; } }); $("#next").click(function(){ //var index = 0; $(div).children().eq(++index).fadeIn().siblings().hide(); //index++; if(index==$(div).children().size()-1) { //alert("最后一張"); index=-1; } }); } tabit("#con") } </script>
三、css代碼如下:
<style type="text/css"> li { border : 1px solid #C4C2C2; color: #466BAE; cursor: pointer; float: left; font-weight: bold; height: 30px; line-height: 30px; text-align: center; width: 50px; text-decoration: none; list-style-type: none; margin:0px; } ul { margin:2px; } .active { background: #fff; font-weight:600; border-bottom:2px solid #8db2e3; } .hide{ display:none; } .red{ background-color:#F00; } .con{ width:720px; min-width:450px; min-height:300px; overflow:hidden; border: solid 1px #CCCCCC; margin:5px auto; } </style>
這里並沒有用插件顯示,而是直接用jquery進行圖片是瀏覽。效果也不是很好。功能還算是到位了吧。因為ppt導出的圖片默認名字為連續編號的,所以可以很方便的讀取。
當ppt預覽結束后,將臨時文件夾刪除即可。
