

官网地址:https://www.onlyoffice.com/
中文文档地址:https://api.onlyoffice.com/zh/editors/basic
本地镜像:documentserver:1.0(对应官方软件版本:6.4.2)





dockerpulldocumentserver:1.0docker run -itd -p 8014:80 --restart=always -e JWT_ENABLED=false -v /data1/onlyoffice/files/:/var/lib/onlyoffice/documentserverexample/files/documentserver:1.0version:"3"services: nullonlyoffice: nullimage:documentserver:1.0environment: - JWT_ENABLED=falsevolumes: - /data1/onlyoffice/files/:/var/lib/onlyoffice/documentserverexample/files/deploy: nullreplicas:1restart_policy: nullcondition: anyports: - 8014:80











@Getter@Setter@ApiModel(value="OnlyOfficePreviewVo对象", description="onlyoffice预览组件所需参数")publicclass OnlyOfficePreviewVo implements Serializable {privatestatic final long serialVersionUID = 1L;@ApiModelProperty(value = "服务端url")privateString documentServerUrl;@ApiModelProperty(value = "文件类型")privateString fileType;@ApiModelProperty(value = "文件标题")privateString title;@ApiModelProperty(value = "文件网络位置")privateString url;@ApiModelProperty(value = "文档类型")privateString documentType;/** * 构建文件预览对象 * * @param documentServerUrl onlyoffice文件服务端地址(必传) * @param url 文件网络地址(必传,可以在网页上下载的文件地址) * @param title 文件标题(非必传,用于展示页面上的文件标题) * @return 文件预览对象 */publicstatic OnlyOfficePreviewVo build(String documentServerUrl, String url, String title) { OnlyOfficePreviewVo previewVo = new OnlyOfficePreviewVo(); previewVo.setDocumentServerUrl(documentServerUrl); previewVo.setUrl(url); previewVo.setTitle(title); String suffix = StrUtil.subAfter(title, ".", Boolean.TRUE); Optional<OnlyOfficeDocumentType> optional = OnlyOfficeDocumentType.of(suffix);if (optional.isPresent()) { OnlyOfficeDocumentType documentType = optional.get();// pdf文件不需要文档类型if (documentType != OnlyOfficeDocumentType.PDF) { previewVo.setDocumentType(documentType.type); } previewVo.setFileType(suffix); }return previewVo; }publicenum OnlyOfficeDocumentType {/** * 文本文档 */ WORD("word", Sets.newHashSet("doc", "docm", "docx", "docxf", "dot", "dotm", "dotx", "epub", "fb2", "fodt", "htm", "html", "mht", "mhtml", "odt", "oform", "ott", "rtf", "stw", "sxw", "txt", "wps", "wpt", "xml")),/** * 电子表格 */ CELL("cell", Sets.newHashSet("csv", "et", "ett", "fods", "ods", "ots", "sxc", "xls", "xlsb", "xlsm", "xlsx", "xlt", "xltm", "xltx", "xml")),/** * 演示文稿 */ SLIDE("slide", Sets.newHashSet("dps", "dpt", "fodp", "odp", "otp", "pot", "potm", "potx", "pps", "ppsm", "ppsx", "ppt", "pptm", "pptx", "sxi")),/** * 便携式文档格式 */ PDF("pdf", Sets.newHashSet("djvu", "oxps", "pdf", "xps")) ;publicStringtype;public Set<String> fileTypes; OnlyOfficeDocumentType(Stringtype, Set<String> fileTypes) {this.type = type;this.fileTypes = fileTypes; }/** * 类型转换 */publicstatic Optional<OnlyOfficeDocumentType> of(String suffix){return Arrays.stream(OnlyOfficeDocumentType.values()).filter(val -> val.fileTypes.contains(suffix)).findFirst(); }}–返回示例 {"success": null,"errorCode": 0,"traceId": "a78e20a3da5a4e829c106a439ea9af00","message": null,"data": {"documentServerUrl": "http://192.168.100.117:8014/","fileType": "xlsx","title": "2024-02统计表.xlsx","url": "","documentType": "cell" }}页面上获取,修改ip地址和端口号即可在页面上下载

/** * 获取文件外链 * * @param objectPath 目标对象路径 * @param expires 过期时间 <=expires 秒 (外链有效时间(单位:秒)) * @return 文件网络地址 * @throws Exception */public String getObjectUrl(String objectPath, Integer expires) throws Exception { GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder().method(Method.GET) .bucket(minioProperties.getBucketName()).object(objectPath).expiry(expires).build();return minioClient.getPresignedObjectUrl(args); }const loadScript = async (url, id) =>new Promise((resolve, reject) => {try {if (document.getElementById(id)) {if (window.DocsAPI) return resolve(null);const intervalHandler = setInterval(() => {if (!window.DocsAPI) return; clearInterval(intervalHandler);return resolve(null); }, 500); } else {const script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("id", id); script.onload = resolve; script.onerror = reject; script.src = url; script.async = true;document.body.appendChild(script); } } catch (e) {console.error(e); } });export default loadScript;



往期推荐
分享
收藏
点赞
在看

夜雨聆风