在做后台管理系统的时候,经常需要上传文件,常用的文件类别基本上就是office三大件。文件上传成功后,往往需要预览。
此时可以通过office online插件来实现office文件的预览效果。
下面是效果图:由于我暂时没有找到线上的powerpoint的文档链接,因此效果图依然是展示的word的文档,使用方法都是完全一样的。
直接上代码:
<div style="display:flex;">
<iframe
src="https://view.officeapps.live.com/op/view.aspx?src=https://physics.nankai.edu.cn/_upload/article/6b/7c/8fe84466415a8e5d48a29c5e08a6/1ea96f13-3367-4ea7-a77f-85b0ec15e121.doc"
width="100%"
height="600px"
frameborder="1"
></iframe>
<iframe
src="https://view.officeapps.live.com/op/view.aspx?src=https://physics.nankai.edu.cn/_upload/article/files/b2/42/e1f28f964ffd8ec534034429bf79/d7a385f5-65a6-4b98-b98a-cfab9b166549.xls"
width="100%"
height="600px"
frameborder="1"
></iframe>
<iframe
src="https://view.officeapps.live.com/op/view.aspx?src=https://physics.nankai.edu.cn/_upload/article/6b/7c/8fe84466415a8e5d48a29c5e08a6/1ea96f13-3367-4ea7-a77f-85b0ec15e121.doc"
width="100%"
height="600px"
frameborder="1"
></iframe>
</div>
通过iframne标签可以直接用于文件的预览,其中的src属性,传参内容是src="https://view.officeapps.live.com/op/view.aspx?src=url"
其中的url是文档的线上地址
width是宽度,height是高度,framborder是边框宽度
最终效果如上所示。
原文链接:https://blog.csdn.net/yehaocheng520/article/details/120970679