ARTICLE · 1412010
office在线预览和编辑-onlyoffice
office在线预览和编辑-onlyofficeonlyoffice安装 ds-docservice ds-converter ds-example ds-adminpanel 
项目中集成
可参考官方安装文档:
https://helpcenter.onlyoffice.com/zh/docs/installation/docs-community-install-centos.aspx
系统要求
- CPU
双核 2 GHz 或更高 - 内存
至少 2 GB,但取决于主机操作系统。更多更好 - 硬盘
至少 40 GB 的可用空间 - 交换分区
至少 4 GB,但取决于主机操作系统。更多更好 - 操作系统
CentOS Stream 9,RHEL 8,或 RHEL 9 - 其他要求
- PostgreSQL
版本 12.9 或更高 - NGINX
版本 1.3.13 或更高 - RabbitMQ
需要提前安装nginx,rabbitmq,pgsql(可用msql代替),
数据库脚本在git下server工程的schema下
git地址: https://github.com/ONLYOFFICE/server
安装完又如下几个服务
重启服务 systemctl restart ds-docservice ds-converter ds-example如需配置数据库和mq的地址,运行如下
documentserver-configure.sh会出现如下界面,根据提示一步步完成配置

也可以通过修改配置文件修改数据库配置,onlyoffcie配置文件/etc/onlyoffice/documentserver/local.json
推荐使用documentserver-configure.sh初始化配置
<!DOCTYPE html><htmllang="zh-CN"><head><metacharset="UTF-8"><title>OnlyOffice 文档编辑</title><!-- 1. 引入 OnlyOffice 前端 SDK --><scriptsrc="http://你的OnlyOfficeIP/web-apps/apps/api/documents/api.js"></script><style>#edit-container {width: 100%;height: 900px;border: 1px solid #eee;}</style></head><body><divid="edit-container"></div><script>var docEditor = new DocsAPI.DocEditor("edit-container", {document: {fileType: "docx",key: "unique-file-key-7890", // 唯一标识,文件更新需更换title: "测试Word文档.xlsx",url: "http://你的文件服务器/files/download?fileId=456" // 文件下载接口},documentType: "spreadsheet", // 文档类型:spreadsheet(excel)/text(word)/presentation(ppt)editorConfig: {mode: "edit", // 编辑模式(核心配置) 预览模式:viewlang: "zh-CN",user: {name: "编辑用户",id: "user-123" // 用户ID(协作时区分不同编辑者)},// 编辑模式必填:回调接口,接收OnlyOffice推送的修改后文件callbackUrl: "http://你的文件服务器/files/save?fileId=456",// 可选:自定义工具栏(隐藏不需要的功能)},token: onlyofficeToken, // 核心:将 Token 传入预览器width: "100%",height: "100%",// 协作配置(可选,多人实时编辑)collaborative: true});// 监听编辑事件(可选)docEditor.on("onDocumentStateChange", function(event) {console.log("文档状态变更:", event.data);});</script></body></html>
生成jwt token,需要额外参数
{"document": {"key": "unique-file-key-123","title": "测试文档.xlsx","url": "文件url"},"editorConfig":{"mode": "edit","callbackUrl": "xxx"}}
编辑模式需要增加editorconfig参数
编辑模式需要修改local.json,在service.CoAuthoring节点下新增如下配置
"callback": {"save": {"timeout": 120000,"maxAttempts": 3,"delay": 1000,"enabled": true}}
编辑模式需要在editorconfig增加强制保存,才能触发回调服务















































































