以html形式显示(word,excel,ppt)总结

一、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预览结束后,将临时文件夹删除即可。

posted @ 2013-01-10 15:21  网无忌  阅读(10393)  评论(0编辑  收藏  举报