onlyOffice官網:https://api.onlyoffice.com/
docker鏡像安裝onlyOffice
拉取onlyOffice鏡像
docker pull hub.c.163.com/gongzh/onlyoffice:latest
運行
docker run -i -t -d -p 8702:80 hub.c.163.com/gongzh/onlyoffice
如果正式使用onlyOffice,可以將容器中的相關目錄映射到本機的mu目錄,方便查看
例如一下目錄:
-v ~/onlyoffice/documentserver/logs:/var/log/onlyoffice \
-v ~/onlyoffice/documentserver/data:/var/www/onlyoffice/Data \
-v ~/onlyoffice/documentserver/sdkjs-plugins:/var/www/onlyoffice/documentserver/sdkjs-plugins \
-v ~/onlyoffice/documentserver/lib:/var/lib/onlyoffice onlyoffice/documentserver
訪問
本機地址:http://localhost:8702/welcome/, 看到如下頁面,表示已經安裝好了
如何通過onlyOffice在線編輯word
第一步,我們寫個簡單的html文件,引用本地onlyOffice的js文件,我本地是:http://localhost:8702/web-apps/apps/api/documents/api.js,然后寫上網關上相關javascript腳本的內容(手動設置編輯框的高和寬),具體如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://localhost:8702/web-apps/apps/api/documents/api.js"></script>
</style>
</head>
<body>
<div id="placeholder" class = "nav"></div>
<script language="javascript" type="text/javascript">
new DocsAPI.DocEditor("placeholder", {
"document": {
"fileType": "docx",
"key": "12NAFE",
"title": "test6.docx",
"url": "你需要編輯word文件的url"
},
"documentType": "text",
"width": "1600px",
"height": "900px",
"editorConfig": {
"callbackUrl": "編輯word后保存時回調的地址,這個api需要自己寫了,將編輯后的文件通過這個api保存到自己想要的位置"
},
"permissions": {
"comment": true,
"download": true,
"edit": true, (文件是否可以編輯,false時文件不可編輯)
"fillForms": true,
"print": true,
"review": true
}
});
</script>
</body>
</html>
寫完html文件后,我們打開,效果如下: