-
docker环境安装一个minio,minio不是本章重点,就不提供细节了,大概过程参考【docker】【minio】
也可以用其他文件服务代替,只要能提供访问文件的url即可 - 【安装only office】或【参考这里】示例中我们把only ofice代理到http://localhost:800
-
要实现在线编辑word模板,首页要实现文件在线预览
预览是比较简单的,保证api.js和tmp.docx能访问即可
<script src="http://127.0.0.1:800/web-apps/apps/api/documents/api.js"></script> <div id="ds_frame"></div> <script> // 编辑器配置项,完整配置项参见:https://api.onlyoffice.com/editors/config/ const editorConfig = { // 编辑器宽度,也可以设置成百分比,不过要父容器设定具体宽度 width: 1200, // 编辑器高度 height: 800, // 编辑器类型,支持 word、cell(表格)、slide(PPT) documentType: 'word', // 文档配置 document: { // 当前文档类型 fileType: 'docx', // 文档标识符 key: 'test2.docx', // 文档地址,绝对路径 url: 'http://../tmp.docx', // 文档标题 title: '测试文档二.docx', // 权限,每个要打开的文档都可以设置独立的权限 permissions: { // 启用评论 comment: false, // 启用下载 download: true, // 启用编辑 edit: true, // 启用导出 print: true, // 启用预览 review: true } }, editorConfig: { // 回调地址 //callbackUrl: 'http://IP/api/v1/onlyoffice/callback', // 设置语言 lang: 'zh-CN', // 添加用户信息 user: { group: '技术部', id: 'al-01', name: '程序员' }, // 模板列表 templates: [], // customization 字段相关配置详解:https://api.onlyoffice.com/editors/config/editor/customization customization: { // 强制保存 forcesave: true, features: { // 关闭拼写检查 spellcheck: false } } } } var docEditor = new DocsAPI.DocEditor("ds_frame", editorConfig); </script>
打开html后大概是这样
下一步【在线编辑与占位符】