LoadWebOffice实现在线编辑Word

LoadWebOffice实现在线编辑Word

1.准备工作

2.代码块

LoadWebOffice目前适用于IE浏览器,火狐和谷歌浏览器要想使用需要安装Firefox ActiveX Plugin,下面的LoadWebOffice.js内容代码火狐和谷歌部分因需求变动未进行测试。

  • (1).LoadWebOffice.js内容
var s = "";
if(navigator.userAgent.indexOf("MSIE")>0){
    s = "<OBJECT id='WebOffice1' align='middle' style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT:768px'"
    + "classid=clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5> codebase='Common/weboffice.ocx#Version=5,0,0,0'"
    + "</OBJECT>";
}
if(navigator.userAgent.indexOf("Chrome")>0){
    s = "<object id='WebOffice1' type='application/x-itst-activex' align='baseline' border='0'"
    + "style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 768px'"
    + "clsid='{E77E049B-23FC-4DB8-B756-60529A35FAD5}' codebase='Common/weboffice.ocx#Version=5,0,0,0'"
    + "event_NotifyCtrlReady='WebOffice1_NotifyCtrlReady'>"
    + "</object>";
}


if(navigator.userAgent.indexOf("Firefox")>0){
    s = "<object id='WebOffice1' type='application/x-itst-activex' align='baseline' border='0'"
    + "style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 768px'" 
    + "clsid='{E77E049B-23FC-4DB8-B756-60529A35FAD5}' codebase='Common/weboffice.ocx#Version=5,0,0,0'"
    + "event_NotifyCtrlReady='WebOffice1_NotifyCtrlReady'>"
    + "</object>";
}
document.write(s)
  • (2).js代码
<script language="javascript" event="NOtifyCtrlReady" for="WebOffice1">
        WebOffice1_NotifyCtrlReady();
    </script>
    <script>
        function WebOffice1_NotifyCtrlReady() {
            $.ajax({
                async: false,
                type: "post",
                data: {
                    action: ""
                },
                url: "",
                success: function (data) {
                    path = data.FiledKey;
                    document.all.WebOffice1.LoadOriginalFile(path,"doc");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('请求发生异常!', { icon: 3 });
                }
            });
        }

        //关闭页面时,关闭文件
        function window_onunload() {
            document.all.WebOffice1.Close();
        }
		//个人需求保存方法
        function upload() {
            document.all.WebOffice1.HttpInit();			//初始化Http引擎
            // 添加相应的Post元素 
            document.all.WebOffice1.HttpAddPostString("DocTitle", "test1");
            document.all.WebOffice1.HttpAddPostString("DocID", "");
            document.all.WebOffice1.HttpAddPostString("DocType", "doc");
            document.all.WebOffice1.HttpAddPostCurrFile("DocContent", "");		// 添加文件
			//请求路径
            var result = document.all.WebOffice1.HttpPost("");

            if ("succeed" == result) {
                alert("文件上传成功");
            } else
                alert("文件上传失败")
            return_onclick();
        }
    </script>
    //HTML代码
    <body onunload="return window_onunload()">
	    <form id="form1" runat="server">
	        <input type="button" onclick="return upload()" class="layui-btn layui-btn-xs" value="上传文档"/>
	        <br />
	        <br />
	    <script src="../jscss/js/LoadWebOffice.js"></script>
	    </form>
</body>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值