天天看點

以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預覽結束後,将臨時檔案夾删除即可。

寵辱不驚,看庭前花開花落;去留無意,望天上雲卷雲舒

繼續閱讀