zoukankan      html  css  js  c++  java
  • JavaScript实现Word、Excel、PPT在线预览

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
    本文链接:https://blog.csdn.net/qq_27626333/article/details/87890664

    能够实现在线预览,但Word、Excel、PPT文档用同样的方式打开则是默认下载。

    微软office online提供了接口来实现Word、Excel、PPT文档在线预览:

    http://view.officeapps.live.com/op/view.aspx?src=<Document Location>

    查看文档地址Office Web Viewer: View Office documents in a browser。实现在线预览的前提是预览资源必须是公共可访问的,通过联机查看 Office 文档可以测试文件是否可以在线预览。

    /**
     * @description [viewFile 查看文件]
     * @author  ZouMiao
     * @param {String} url [文件地址]
     * @returns {Null} [没有返回]
     */
    export const viewFile = function (url) {
      let onlineViewType = ['doc', 'docx', 'xls', 'xlsx', 'xlsm', 'ppt', 'pptx']
      let fileTypeName = url.substring(url.lastIndexOf('.') + 1, url.length).split('?')[0]
      let isWord = onlineViewType.find((type) => type === fileTypeName)
      if (isWord) {
        url = 'http://view.officeapps.live.com/op/view.aspx?src=' + url
      }
      window.open(url, '_blank')
    }
    
    

      

    在项目中使用在线预览有时报File too large,The file specified is larger than what the Office Online Viewers are configured to support.Reduce the size of the file to view it online.

    File too large Error: The file specified is larger than what the Office Online Viewers are configured to support. Reduce the size of the file to view it online.

    Office Online产品团队的Ryan回复

    The document is too large. Word and PowerPoint documents must be less than 10 megabytes; Excel must be less than five megabytes.

      所以使用Office Online必须注意Word、PPT文件不能大于10M,Excel文件不能大于5M。

  • 相关阅读:
    Ilya Muromets(DP or 思维)
    2018 焦作网络赛 L Poor God Water ( AC自动机构造矩阵、BM求线性递推、手动构造矩阵、矩阵快速幂 )
    上下界的网络流模板
    计蒜客 2018南京网络赛 I Skr ( 回文树 )
    回文树 / 自动机模板
    Nowcoder 练习赛26 D xor序列 ( 线性基 )
    线性基模板
    Tarjan求强连通分量、求桥和割点模板
    Nowcoder 挑战赛23 B 游戏 ( NIM博弈、SG函数打表 )
    第二类斯特林数模板
  • 原文地址:https://www.cnblogs.com/hpx2020/p/11608526.html
Copyright © 2011-2022 走看看