最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to open excel file using JavaScript code without using ActiveX control? - Stack Overflow

programmeradmin7浏览0评论

How to open an Excel document using JavaScript code and without using an ActiveX control object like:

var myApp = new ActiveXObject("Excel.Application");
myApp.workbooks.open("test.xls");

How to open an Excel document using JavaScript code and without using an ActiveX control object like:

var myApp = new ActiveXObject("Excel.Application");
myApp.workbooks.open("test.xls");
Share Improve this question edited Dec 10, 2017 at 13:15 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Jan 4, 2012 at 15:42 Vinoth KumarVinoth Kumar 111 gold badge1 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

I tried below option and it worked. Just prepend ms-excel:ofe|u before the url of xlsx file. It works in IE, Chrome other browsers I have not tested. This is what Microsoft One Drive online portal uses for opening encrypted xlxs files on client machines.

<a onclick="window.open('ms-excel:ofe|u|http://localhost/iis-server/test.xlsx')"> Open Excel </a>

I don't think this is possible. JavaScript, when running in the browser, should be sandboxed to the browser's process and not able to launch other applications.

You might try relying on the browser knowing that .XLS files are opened by Excel and have it change window.location to a URL that is an Excel file. But the user would have had to set up their browser and tell it that Excel files are opened by Excel and, yes, when I go to an Excel file, please open it in Excel rather than saving it to disk.

It's possible to open .xlsx files with Javascript because they are ZIP packages. This has been experimented with XForms: http://www.w3/munity/xformsusers/2012/12/19/editing-zip-with-xforms/

发布评论

评论列表(0)

  1. 暂无评论