老師讓看這個……雖然不知道要幹啥
文章目錄
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