版權聲明:本文為博主原創文章,遵循 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。