实现在线预览文档

使用微软的预览接口来实现在线预览Word,Excel,PowerPoint格式的文档

最终打开方式:

'https://view.officeapps.live.com/op/view.aspx?src=' + url

其中,

  1. 'https://view.officeapps.live.com/op/view.aspx?src=' 是微软预览接口,固定不变;

  2. url 是上传文件到后台后返回的文件路径file_url(带https/http)

实现方式:

  1. 打开新窗口预览文件:eg:

<a target='_blank'  href='https://view.officeapps.live.com/op/view.aspx?src=file_url'>预览文件</a>
  1. 当前页面预览文件:

<iframe src='https://view.officeapps.live.com/op/view.aspx?src=file_url' />

上述方法适用于Word,Excel,PowerPoint,但是不适用于PDF文件的预览,预览PDF文件可以:

  1. a标签直接预览

<a target='_blank'  href='file_url'>预览PDF文件</a>
  1. 通过pdf.js插件进行预览

posted @ 2020-08-17 13:52  _JZYU  阅读(1543)  评论(0编辑  收藏  举报