实现在线预览文档

使用微软的预览接口来实现在线预览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插件进行预览

声明:此资源由本博客收集整理,只用于记录心得和交流学习,请勿用作它途。如有侵权,请联系, 删除处理。
原文地址:https://www.cnblogs.com/jzyu/p/13517202.html