参考:https://blog.csdn.net/didididi123321/article/details/89140596
iWebOffice2015:(可打开word,excel文件)
<script src="office/WebOffice.js"></script>
<script src="office/jquery.min.js"></script>
···
<div id="OfficeDiv" style=" 100%; height: 100%;">
<script src="office/iWebOffice2015.js"></script>
</div>
···
<script type="text/javascript"> var WebOfficeObj = new WebOffice2015(); //创建WebOffice对象 var baseUrl = sessionStorage.getItem('downFile');//后端路径 var fileName = sessionStorage.getItem('fileName');//文件相对后端路径 var ifPrint = sessionStorage.getItem('ifPrint');//是否弹出打印 setTimeout(function () { WebOfficeObj.webUrl = baseUrl; WebOfficeObj.ServerUrl = baseUrl; WebOfficeObj.WebOpen2(fileName);//使用金格打开文件 if (ifPrint==='true') { //session存入的是字符 setTimeout(function () { //避免页面加载完,控件还没有加载的情况 WebOfficeObj.WebOpenPrint();//打印弹窗打开 }, 500); } }, 500); </script>
iWebPDF2018:(可打开pdf,ofd文件)
<script src="office/jquery.min.js"></script>
<script type="text/javascript" src="office/function.js"></script>
···
<div region="center" style="height: 100%;"> <script src="office/iWebPDF2018.js"></script> </div> ··· <script> setTimeout(function () { var baseUrl = sessionStorage.getItem('downFile'); var name = sessionStorage.getItem('fileName'); var ifPrint = sessionStorage.getItem('ifPrint'); if (ifPrint==='false') { HideShowBar(); //显隐工具栏 } HideShowTabCommandBar(); //显隐左命令栏 iWebPDF2018.Documents.OpenFromURL(baseUrl + name); if (ifPrint==='true') { setTimeout(function () { PrintContent(); //打印弹窗打开 }, 500); } }, 500); </script>