WebOffice安装教程Hello World!(win10 IE打开控件问题)

老师让看这个……虽然不知道要干啥

WebOffice安装教程

环境

操作系统版本:win10
Office版本:Microsoft Office Home and Student 2019

WebOffice控件下载与注册

1、点击这里下载WebOffice.rar
2、将WebOffice.rar所有内容解压至桌面、C盘或D盘等任意盘的根目下。执行后路径如:C:\WebOffice 或 D:\WebOffice 等。(我解压到D:\WebOffice)
3、打开解压后的WebOffice目录,找到 WebOffice_Setup.bat 文件,双击运行,在提示“是”与“否”等对话框时,请选择“是”或“同意”按钮即可。
4、然后弹出了一个安装插件的窗口,点击next:
在这里插入图片描述
5、这里可以选择安装的地址,因为不大我也懒得改,直接next,然后install即可:
在这里插入图片描述

第一个WebOffice程序:Hello World!

1.生成两个html文档

(1)在D盘新建名为WebOfficeTest目录
(2)在WebOfficeTest目录新建index.html和edit.html这两个空白html文档。

2.设计启动页(index.html)

在index.html中加入如下代码:

<a href="WebOffice://|Officectrl|file:///D:/WebOfficeTest/edit.html">查看</a>

注意:上面地址:WebOffice://|Officectrl|file:///C:/WebOfficeTest/edit.html 分成两部份:
第一部份:WebOffice://|Officectrl| 为启用智能窗链接的协议前缀,启用智能窗是为了全面兼容所有浏览器正确运行本示例。
第二部份:file:///C:/WebOfficeTest/edit.html 是打开一个本地网页的传统地址

如果用户使用ie浏览器测试本示例,也可以把上面网址直接写成传统地址形式如下:

<a href="file:///C:/WebOfficeTest/edit.html">查看</a>

用Chrome打开index.html:
在这里插入图片描述
点击“查看”按钮:
在这里插入图片描述
点击“打开WebOfficeProtocol”(因为edit.html为空,所以页面为空):
在这里插入图片描述

3.设计WebOffice控件加载页(edit.html)

在edit.html中加入如下代码:

<html>
<head>
<title></title>
</head>
<script language="javascript">
function OpenDoc()
{
	//取得WebOffice对象
	var WebOffice=document.getElementById("WebOffice");
	//通过对象WebOffice的Open方法打开个一个服务器文档
	//此处服务器文档地址为:http://www.officectrl.com/officecs/temp/file1.doc
	WebOffice.Open("http://www.officectrl.com/officecs/temp/file1.doc",false,"Word.Document");
}
</script>
<!-- 设计按钮,增加点击触发JS函数 -->
<body><div><input type=button onclick="OpenDoc();" value="打开"></div>
<!-- 引入WebOffice对象 -->
<script language="javascript">
if (!!window.ActiveXObject || "ActiveXObject" in window){
document.write('<object classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5" codebase="WebOffice.ocx#Version=2019,1,7,3" id="WebOffice" width="900" height="500" >');
document.write('</object>');}
else
{
document.write('<object id="WebOffice" CLSID="{FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5}" TYPE="application/x-itst-activex"  width=100% height=900></object>');
}
</script>
</body>

用Chrome打开index.html,依旧按上面的步骤操作,到edit.html页面后,页面多了一个按钮,点击按钮:
在这里插入图片描述

4.修改编码

可以看到上面的结果中,“打开”按钮的文字显示乱码,这时候需要我们修改html文件编码,以uft-8进行编码。
修改后的index.html代码如下:

<!DOCTYPE html>
	<html>
	<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<title></title>
	</head>

	<body>
	 <a href="WebOffice://|Officectrl|file:///D:/WebOfficeTest/edit.html">查看</a>
	</body>
	</html>

修改后的edit.html代码如下:

<!DOCTYPE html>
<html>
<head><meta http-equiv="content-type" content="text/html;charset=utf-8">
<title></title>
</head>
<script language="javascript">
function OpenDoc()
{
	//取得WebOffice对象
	var WebOffice=document.getElementById("WebOffice");
	//通过对象WebOffice的Open方法打开个一个服务器文档
	//此处服务器文档地址为:http://www.officectrl.com/officecs/temp/file1.doc
	WebOffice.Open("http://www.officectrl.com/officecs/temp/file1.doc",false,"Word.Document");
}
</script>
<body><div><input type=button onclick="OpenDoc();" value="打开"></div>
<script language="javascript">
if (!!window.ActiveXObject || "ActiveXObject" in window){
document.write('<object classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5" codebase="WebOffice.ocx#Version=2019,1,7,3" id="WebOffice" width="900" height="500" >');
document.write('</object>');}
else
{
document.write('<object id="WebOffice" CLSID="{FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5}" TYPE="application/x-itst-activex"  width=100% height=900></object>');
}
</script>
</body>
</html>

修改之后,再次打开index.html,按上述操作,显示如下:
在这里插入图片描述

Win10 IE打不开WebOffice控件问题

前面的例子都是在Chrome里面进行的,在Win10的IE里面可能出现控件打不开的问题,解决办法参考问题6

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章