使用onlyoffice预览word、excel、ppt、pdf等,可以双击index.html看效果的demo示例

index.html

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>OnlyOffice 文档预览测试</title> <script src="https://chat.xutongbao.top/onlyoffice/web-apps/apps/api/documents/api.js"></script> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 20px; } .container { max-width: 1400px; margin: 0 auto; } .header { background: white; border-radius: 20px; padding: 30px; margin-bottom: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); } .header h1 { font-size: 32px; color: #333; margin-bottom: 10px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; } .header p { color: #666; font-size: 14px; } .test-buttons { background: white; border-radius: 20px; padding: 30px; margin-bottom: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); } .test-buttons h2 { font-size: 20px; color: #333; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; } .buttons-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; } .test-btn { border: 2px solid transparent; border-radius: 15px; padding: 20px; cursor: pointer; transition: all 0.3s ease; text-align: center; background: linear-gradient(white, white) padding-box, linear-gradient(135deg, currentColor, currentColor) border-box; position: relative; overflow: hidden; } .test-btn:hover { transform: translateY(-5px); box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15); } .test-btn.word { color: #2b579a; border-color: rgba(43, 87, 154, 0.3); } .test-btn.word:hover { background: linear-gradient(135deg, rgba(43, 87, 154, 0.1), rgba(43, 87, 154, 0.05)); } .test-btn.excel { color: #1d6f42; border-color: rgba(29, 111, 66, 0.3); } .test-btn.excel:hover { background: linear-gradient(135deg, rgba(29, 111, 66, 0.1), rgba(29, 111, 66, 0.05)); } .test-btn.powerpoint { color: #c43e1c; border-color: rgba(196, 62, 28, 0.3); } .test-btn.powerpoint:hover { background: linear-gradient(135deg, rgba(196, 62, 28, 0.1), rgba(196, 62, 28, 0.05)); } .test-btn.pdf { color: #dc2626; border-color: rgba(220, 38, 38, 0.3); } .test-btn.pdf:hover { background: linear-gradient(135deg, rgba(220, 38, 38, 0.1), rgba(220, 38, 38, 0.05)); } .icon { width: 48px; height: 48px; margin: 0 auto 15px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: white; transition: transform 0.3s ease; } .test-btn:hover .icon { transform: scale(1.1); } .test-btn.word .icon { background: linear-gradient(135deg, #2b579a, #1e3c6e); } .test-btn.excel .icon { background: linear-gradient(135deg, #1d6f42, #15562f); } .test-btn.powerpoint .icon { background: linear-gradient(135deg, #c43e1c, #9a2f14); } .test-btn.pdf .icon { background: linear-gradient(135deg, #dc2626, #b91c1c); } .btn-title { font-size: 16px; font-weight: 600; margin-bottom: 5px; } .btn-desc { font-size: 12px; color: #666; } .preview-area { background: white; border-radius: 20px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); display: none; } .preview-area.active { display: block; } .file-info { background: white; border-radius: 20px; padding: 20px 30px; margin-bottom: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); display: none; align-items: center; justify-content: space-between; } .file-info.active { display: flex; } .file-info-left { display: flex; align-items: center; gap: 15px; flex: 1; } .file-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: white; background: linear-gradient(135deg, #10b981, #059669); } .file-details h3 { font-size: 18px; color: #333; margin-bottom: 5px; } .file-meta { font-size: 12px; color: #666; display: flex; align-items: center; gap: 10px; } .close-btn { padding: 8px 16px; border: 2px solid #e5e7eb; border-radius: 10px; background: white; color: #666; cursor: pointer; font-size: 14px; transition: all 0.3s ease; } .close-btn:hover { border-color: #dc2626; background: rgba(220, 38, 38, 0.05); color: #dc2626; } #onlyoffice-editor { width: 100%; height: calc(100vh - 300px); min-height: 700px; } .loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: calc(100vh - 300px); min-height: 700px; background: #f9fafb; } .spinner { width: 50px; height: 50px; border: 4px solid #e5e7eb; border-top-color: #667eea; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .loading-text { margin-top: 20px; font-size: 18px; color: #333; font-weight: 600; } .error-message { background: #fee2e2; border: 2px solid #fca5a5; border-radius: 15px; padding: 20px; margin-top: 20px; color: #dc2626; display: none; } .error-message.active { display: block; } .supported-formats { background: rgba(102, 126, 234, 0.05); border: 1px solid rgba(102, 126, 234, 0.2); border-radius: 15px; padding: 15px; margin-top: 15px; } .format-title { font-size: 14px; font-weight: 600; color: #333; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; } .formats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; font-size: 12px; color: #666; } .format-item { display: flex; align-items: center; gap: 5px; } .format-label { font-weight: 600; color: #333; } iframe { height: 500px; } </style> </head> <body> <div class="container"> <!-- 标题区域 --> <div class="header"> <h1>📄 OnlyOffice 文档预览测试</h1> <p>支持 Word、Excel、PowerPoint 等多种格式的文档在线预览</p> <!-- 支持格式说明 --> <div class="supported-formats"> <div class="format-title"> ✨ 支持的文件格式 </div> <div class="formats-grid"> <div class="format-item"> <span class="format-label">文档:</span> <span>DOC, DOCX, ODT, RTF, TXT, PDF 等</span> </div> <div class="format-item"> <span class="format-label">表格:</span> <span>XLS, XLSX, ODS, CSV 等</span> </div> <div class="format-item"> <span class="format-label">演示:</span> <span>PPT, PPTX, ODP 等</span> </div> </div> </div> </div> <!-- 测试按钮区域 --> <div class="test-buttons"> <h2>🚀 快速测试</h2> <div class="buttons-grid"> <button class="test-btn word" onclick="loadDocument('word')"> <div class="icon">📝</div> <div class="btn-title">测试 Word</div> <div class="btn-desc">文档编辑器</div> </button> <button class="test-btn excel" onclick="loadDocument('excel')"> <div class="icon">📊</div> <div class="btn-title">测试 Excel</div> <div class="btn-desc">表格编辑器</div> </button> <button class="test-btn powerpoint" onclick="loadDocument('powerpoint')"> <div class="icon">📽️</div> <div class="btn-title">测试 PowerPoint</div> <div class="btn-desc">演示文稿编辑器</div> </button> <button class="test-btn pdf" onclick="loadDocument('pdf')"> <div class="icon">📄</div> <div class="btn-title">测试 PDF</div> <div class="btn-desc">PDF 阅读器</div> </button> </div> </div> <!-- 错误提示 --> <div class="error-message" id="errorMessage"></div> <!-- 文件信息 --> <div class="file-info" id="fileInfo"> <div class="file-info-left"> <div class="file-icon">📄</div> <div class="file-details"> <h3 id="fileName">文档名称</h3> <div class="file-meta"> <span id="fileSize">大小</span> <span>•</span> <span id="fileType">类型</span> <span>•</span> <span id="fileTime">时间</span> </div> </div> </div> <button class="close-btn" onclick="closePreview()">✕ 关闭</button> </div> <!-- 预览区域 --> <div class="preview-area" id="previewArea"> <div id="onlyoffice-editor"></div> </div> </div> <script> let docEditor = null; // 文档配置 const documents = { word: { url: 'https://static.xutongbao.top/ai/onlyoffice/1769051991957_%E6%B5%8B%E8%AF%95%E4%B8%80%E4%B8%8B.docx', documentType: 'word', fileName: '测试文档.docx', fileType: 'docx', size: '240 KB', icon: '📝' }, excel: { url: 'https://static.xutongbao.top/ai/onlyoffice/1769053651678_1.xlsx', documentType: 'cell', fileName: '测试表格.xlsx', fileType: 'xlsx', size: '100 KB', icon: '📊' }, powerpoint: { url: 'https://static.xutongbao.top/ai/onlyoffice/1769053694718_1.pptx', documentType: 'slide', fileName: '测试演示文稿.pptx', fileType: 'pptx', size: '500 KB', icon: '📽️' }, pdf: { url: 'https://static.xutongbao.top/ai/onlyoffice/1769054138134_%E6%B5%8B%E8%AF%95%E4%B8%80%E4%B8%8B.pdf', documentType: 'word', fileName: '测试文档.pdf', fileType: 'pdf', size: '1 MB', icon: '📄' } }; // 加载文档 function loadDocument(type) { const doc = documents[type]; if (!doc) { showError('未找到对应的文档配置'); return; } // 隐藏错误提示 hideError(); // 销毁旧的编辑器 if (docEditor) { try { docEditor.destroyEditor(); docEditor = null; } catch (error) { console.warn('销毁旧编辑器失败:', error); } } // 清空容器 const container = document.getElementById('onlyoffice-editor'); container.innerHTML = '<div class="loading"><div class="spinner"></div><div class="loading-text">正在加载预览...</div></div>'; // 显示文件信息 document.getElementById('fileName').textContent = doc.fileName; document.getElementById('fileSize').textContent = doc.size; document.getElementById('fileType').textContent = doc.documentType === 'word' ? 'Word 文档' : doc.documentType === 'cell' ? 'Excel 表格' : doc.documentType === 'slide' ? 'PowerPoint 演示' : 'PDF 文档'; document.getElementById('fileTime').textContent = new Date().toLocaleTimeString(); document.querySelector('.file-icon').textContent = doc.icon; document.getElementById('fileInfo').classList.add('active'); // 显示预览区域 document.getElementById('previewArea').classList.add('active'); // 延迟初始化编辑器 setTimeout(() => { initOnlyOfficeEditor(doc); }, 100); } // 初始化 OnlyOffice 编辑器 function initOnlyOfficeEditor(doc) { if (!window.DocsAPI) { showError('OnlyOffice API 未加载,请检查网络连接'); return; } const container = document.getElementById('onlyoffice-editor'); container.innerHTML = ''; const config = { documentType: doc.documentType, document: { fileType: doc.fileType, key: `${Date.now()}-${Math.random().toString(36).substring(7)}`, title: doc.fileName, url: doc.url, }, editorConfig: { mode: 'edit', lang: 'zh-CN', user: { id: 'test-user', name: '测试用户', }, }, width: '100%', height: '100%', events: { onDocumentReady: () => { console.log('OnlyOffice 文档加载完成'); }, onAppReady: () => { console.log('OnlyOffice 应用已准备就绪'); }, onError: (event) => { console.error('OnlyOffice 错误:', event); showError('文档加载失败,请重试'); } }, }; try { docEditor = new window.DocsAPI.DocEditor('onlyoffice-editor', config); console.log('OnlyOffice 编辑器初始化成功'); } catch (error) { console.error('初始化编辑器失败:', error); showError('编辑器初始化失败: ' + error.message); } } // 关闭预览 function closePreview() { if (docEditor) { try { docEditor.destroyEditor(); docEditor = null; } catch (error) { console.warn('销毁编辑器失败:', error); } } document.getElementById('fileInfo').classList.remove('active'); document.getElementById('previewArea').classList.remove('active'); document.getElementById('onlyoffice-editor').innerHTML = ''; } // 显示错误 function showError(message) { const errorEl = document.getElementById('errorMessage'); errorEl.textContent = '❌ ' + message; errorEl.classList.add('active'); } // 隐藏错误 function hideError() { const errorEl = document.getElementById('errorMessage'); errorEl.classList.remove('active'); } // 检查 API 是否加载 window.addEventListener('load', () => { if (!window.DocsAPI) { console.warn('OnlyOffice API 未加载'); } else { console.log('OnlyOffice API 已加载'); } }); </script> </body> </html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1200948.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【网络安全】你必须知道的几个网络安全概念

我们大家都知道网络安全的重要性&#xff0c;但对于网络安全相关知识了解的少之又少。今天我们小编就告诉你几个网络安全概念&#xff0c;以便大家了解。 一、安全 Web 网关 安全 Web 网关已经从其过去优化互联网带宽的目的演变为保护用户免受来自互联网的恶意内容的侵害。诸…

YOLOv13 RAB(Residual Attention Block)原理深度解析:多级残差 + 空间注意力的创新设计与应用

RAB模块原理深度解析:YOLOv13中的创新与应用教程 文章目录 RAB模块原理深度解析:YOLOv13中的创新与应用教程 1. 引言:深度学习架构演进与YOLOv13的创新 1.1 目标检测任务的挑战与YOLO系列的崛起 1.2 C2f模块: 1.3 RAB模块:创新驱动的性能飞跃 2. 背景回顾:YOLO中的C2f模块…

绝缘材料高压漏电起痕试验仪BLD-6000V

绝缘材料高压漏电起痕试验仪BLD-6000V&#xff1a;绝缘材料安全测试的全面指南 电痕化——电气安全的隐形威胁在潮湿、多尘或盐雾环境中&#xff0c;绝缘材料表面可能悄然形成导电碳化通道&#xff0c;这一过程称为漏电起痕&#xff08;Electrical Tracking&#xff09;。它并…

2026年高速印刷机加工厂选择:这些技巧助你避坑,市面上高速印刷机排名聚焦优质品牌综合实力排行

随着包装行业数字化转型加速,高速印刷机作为核心生产设备,其技术迭代与供应链稳定性直接影响企业竞争力。然而,市场上加工厂良莠不齐,部分企业存在技术滞后、服务响应慢、交付周期长等问题,导致采购方陷入“选型难…

毕设数据不够?YOLO自动数据增强实战:一键生成图片+XML,小样本也能训模型

文章目录 一、为什么自动数据增强是毕设的“数据救星”? 二、自动数据增强的“生成逻辑”:让数据“无中生有” 三、实战:自动生成带标注的图片与xml,三步搞定 1. 第一步:工具准备与目录结构 2. 第二步:自动增强脚本实现(复制即用) 3. 第三步:执行增强与数据集整合 四、…

【全网最全】sql注入详解

目录 前言 一、漏洞原因分析 二、漏洞危害 三、sql注入防范 四、如何挖掘sql注入漏洞 五、常见的注入手法 联合查询(union注入) 报错注入 基于布尔的盲注 基于时间的盲注 HTTP头注入 宽字节注入 堆叠查询 二阶注入 六、sql注入getshell的几种方式 前言 SQL注入…

基于Java的山区防洪治理智慧管理系统的设计与实现全方位解析:附毕设论文+源代码

1. 为什么这个毕设项目值得你 pick ? 山区防洪治理智慧管理系统结合了Java、SpringMVC及MySQL等技术&#xff0c;旨在为用户提供一个全面的解决方案。该系统不仅涵盖了行政区划管理、监测站点管理和会员管理等多个功能模块&#xff0c;还实现了水位监测、降雨量监测和灾害事件…

YOLOv8 + RepVGG + QueryDet 小目标检测实战指南:遥感图像检测从原理到落地

文章目录 一、引言与技术背景 1.1 目标检测技术的重要性与广泛应用 1.2 深度学习在目标检测领域的革命性进展 1.3 YOLO系列算法的发展历程与YOLOv8的技术创新 二、实验环境搭建与数据集深度分析 2.1 硬件环境配置的重要性与最佳实践 2.2 软件环境配置与依赖管理最佳实践 2.3 遥…

Redis 淘汰策略切换会对现有数据有何影响?深度解析 + Spring Boot 实战避坑指南

视频看了几百小时还迷糊&#xff1f;关注我&#xff0c;几分钟让你秒懂&#xff01;在 Redis 运维中&#xff0c;你可能会遇到这样的场景&#xff1a;初期配置了 volatile-lru&#xff0c;但发现没设过期时间的 key 越来越多&#xff0c;内存快爆了业务从“纯缓存”变为“混合存…

科研论文写作助手:8款智能翻译与文本改进工具排行

&#xfffd;&#xfffd; 8款英文论文AI写作工具核心对比 工具名称 核心功能 处理速度 适合场景 独特优势 aibiye 降AIGC率查重 20分钟 学术论文优化 适配知网/维普检测规则 aicheck AIGC检测降重 20分钟 AI生成内容处理 双重检测降重一体化 askpaper 学术风格…

论文优化工具指南:人工智能翻译与润色功能TOP8

&#xfffd;&#xfffd; 8款英文论文AI写作工具核心对比 工具名称 核心功能 处理速度 适合场景 独特优势 aibiye 降AIGC率查重 20分钟 学术论文优化 适配知网/维普检测规则 aicheck AIGC检测降重 20分钟 AI生成内容处理 双重检测降重一体化 askpaper 学术风格…

解决uni-app中echarts图表自带的事件(点击,拖拽,滑动,悬停...)失效问题

问题原因&#xff1a;uniapp中的wx变量污染了echarts中的wx变量。 解决办法 方法1&#xff1a;在main.js中移除window中的wx对象&#xff0c;或者置空微信对象 //解决echarts在h5、app中tooltips及部分功能失效问题 window.wx null delete window.wx注意&#xff1a;这种办法虽…

模块化多电平变换器MMC两种调制策略实现仿真分享

模块化多电平变换器MMC两种调制策略实现&#xff08;交流3000V-直流5000V整流&#xff09;仿真&#xff0c;单桥臂二十子模块&#xff0c;分别采用最近电平逼近NLM与载波移相调制CPS-PWM实现&#xff0c;仿真中使用环流抑制&#xff0c;NLM中采用快速排序&#xff0c;两个仿真动…

YOLOv13 性能核弹级升级!DCMB 模块实测,mAP 最高暴涨 13.88%

效果炸裂,绿色线条为添加DCMB模块,蓝色为原模型。 map提升9.23个点,map50 文章目录 移植 创建 ultralytics\cfg\models\v13\yolov13-DCMB.yaml 修改ultralytics\nn\tasks.py 修改ultralytics/nn/modules/__init__.py 修改ultralytics\nn\modules\block.py DCMB (Dynamic Con…

2026汽车制造轴流风机可靠品牌推荐榜

2026汽车制造轴流风机可靠品牌推荐榜行业背景与选型痛点据《2026-2030中国工业通风设备行业发展白皮书》数据显示,2026年我国工业轴流风机市场规模达326亿元,年复合增长率保持8.7%的稳定态势。 其中汽车制造、冶金等…

AI 技术在英语口语的应用

AI 技术在英语口语学习中的应用已经从早期的“死板纠错”进化到了全感知、端到端的沉浸式交互阶段。现在的 AI 能够模拟真实的人类老师&#xff0c;甚至在情绪支持和语境理解上超过了普通外教。以下是 2026 年 AI 英语口语学习的核心应用深度解析&#xff1a;1. 多模态交互与实…

基于Java的岗位变动智慧管理系统的设计与实现全方位解析:附毕设论文+源代码

1. 为什么这个毕设项目值得你 pick ? 告别“烂大街”选题&#xff01;本系统设计了一套基于Java的岗位变动智慧管理系统&#xff0c;涵盖了会员管理、考勤记录、绩效考核等模块。相比传统选题&#xff0c;它具有更高的创新性和实用性&#xff1a;首先&#xff0c;在功能上实现…

2026年江苏招标采购平台服务权威推荐榜单:招标采购信息/电子招标采购/招标采购网/招标采购工具/招标采购方式提供商精选

在国家加快建设全国统一大市场的政策指引下,江苏省作为经济大省,其招标采购市场正经历着深刻变革。根据行业数据,电子化招标采购的渗透率已超过80%,选择一家具备合规资质、技术先进且服务网络健全的线上平台,已成…

电子时钟设计

2 系统结构 整个电子时钟系统电路可分为五大部分&#xff1a;中央处理单元&#xff08;CPU&#xff09;、电源电路部分、显示部分、键盘输入部分、温度采集部分。 2&#xff0e;1 中央处理单元 CPU选用AT89C—2051对整个系统进行控制&#xff1a; 1&#xff09;它将定时数据输出…

突发!1301 本期刊被集体预警!全球三大OA出版商旗下所有期刊被拉入黑名单

据相关学者分享&#xff0c;澳门城市大学近日已正式发布《预警期刊目录》&#xff0c;其中Hindawi、MDPI、Frontiers三家出版商出版的期刊全部在列。预警期刊目录 Early Warning Journal List 经2025年11月19日2025-2026学年科研专责小组第一次会议通过1.预警期刊目录来源&…