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");

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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.

8 Comments

ok, If I use Active X control to Open Excel then Is there any way to turn off ActiveXcontrol alert internally? I am not asking about browser settings change! I mean setting trusted location etc.
If the user has your site listed in their trusted locations and has the ActiveX control marked as safe, then, yes, you should be able to do this without popping up an error. But it's up the user to configure their computer this way.
Not in JavaScript. If that were possible it would defeat the object of the alert. If this is for an internal project and you need to use a browser-based script then you could look at using an HTA instead. It's an older technology but works ok when you need to run code which would normally run into sand boxing issues in a browser.
@TimWilliams correct -- I didn't mean you could do this in JS. To get the behavior the OP is looking for you'd have have an ActiveX control, which is trusted along with the site.
@tkone how to configure computer for trusted location?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.