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

简介: 一、word篇。 思路:直接利用word.application提供的方法将word转存为html格式,但是排版会出现错位现象(暂时定好容器宽度可以解决。偷懒)。 function saveword(){ try{ var WordApp=new ActiveXObject("Word.

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


宠辱不惊,看庭前花开花落;去留无意,望天上云卷云舒
目录
相关文章
|
4月前
|
Python
Python 将PowerPoint (PPT/PPTX) 转为HTML
使用Python将PowerPoint转换为HTML以适应网络分享。需安装`Spire.Presentation for Python`库,通过`pip install Spire.Presentation`。示例包括:1) 全部转换,使用`Presentation.SaveToFile()`方法;2) 转换特定幻灯片,通过`Presentation.Slides[]`获取幻灯片再保存。代码示例展示了具体操作步骤。
|
11天前
|
C# 开发者 Windows
WPF遇上Office:一场关于Word与Excel自动化操作的技术盛宴,从环境搭建到代码实战,看WPF如何玩转文档处理的那些事儿
【8月更文挑战第31天】Windows Presentation Foundation (WPF) 是 .NET Framework 的重要组件,以其强大的图形界面和灵活的数据绑定功能著称。本文通过具体示例代码,介绍如何在 WPF 应用中实现 Word 和 Excel 文档的自动化操作,包括文档的读取、编辑和保存等。首先创建 WPF 项目并设计用户界面,然后在 `MainWindow.xaml.cs` 中编写逻辑代码,利用 `Microsoft.Office.Interop` 命名空间实现 Office 文档的自动化处理。文章还提供了注意事项,帮助开发者避免常见问题。
35 0
|
2月前
|
Web App开发 前端开发 安全
2024年新一代WebOffice内嵌网页组件,Web网页在线编辑Word/Excel/PPT
WebOffice控件面临兼容性、用户体验和维护难题。随着浏览器更新,依赖插件的技术不再适用,如Chrome不再支持NPAPI和PPAPI。产品普遍不支持多版本Office并存,定制能力弱,升级复杂。猿大师办公助手提供了解决方案,它兼容多种浏览器,包括最新版和国产浏览器,不依赖插件,支持文档对比,具有丰富的功能和接口,兼容多种Office版本,允许源码级定制,提供终身技术支持,并实现静默在线升级。适用于多种行业和操作系统。
103 3
VBA如何用Excel数据批量生成Word文档
VBA|用Excel数据批量生成并修改用模板创建的Word文档
|
3月前
使用LabVIEW打开默认应用程序中的文档(PDF,Word,Excel,Html)
使用LabVIEW的&quot;Open a Document on Disk.vi&quot;,存于&lt;LabVIEW&gt;\vi.lib\Platform\browser.llb,可让默认应用打开硬盘文档。此VI仅基础打开功能,高级控制推荐LabVIEW Report Generation Toolkit或ActiveX。注意:避免版本升级问题,最好将VI复制到vi.lib外的目录。
|
4月前
|
Java Apache
Java将word、excel文件转成pdf文件
【5月更文挑战第26天】Java将word、excel文件转成pdf文件
1553 1
|
3月前
|
Java Maven
Java在线预览(word转html)--强势推荐
Java在线预览(word转html)--强势推荐
59 0
|
4月前
|
JavaScript Java 测试技术
基于springboot+vue.js的基于HTML5的问卷调查系统附带文章和源代码设计说明文档ppt
基于springboot+vue.js的基于HTML5的问卷调查系统附带文章和源代码设计说明文档ppt
41 0
|
1月前
|
数据可视化 Python
我是如何把python获取到的数据写入Excel的?
我是如何把python获取到的数据写入Excel的?
33 2
|
19天前
|
关系型数据库 MySQL Shell
不通过navicat工具怎么把查询数据导出到excel表中
不通过navicat工具怎么把查询数据导出到excel表中
24 0