4

How to use javascript or jQuery to open an excel html file in excel from the browser?

I've been trying to just use the window.open(href) to open an html excel file. It location on server is: /server/excelfiles/myexcel.xls, and I'm trying to open it in an excel app and not in an active x control in IE browser. Its this even possible to open up a file in the application instead of the browser?

4 Answers 4

2

Two methods:

<a href="/server/excelfiles/myexcel.xls" target="_blank">open myexcel.xls</a> 

or via JS:

function openExcelFile(strFilePath) {
    if (window.ActiveXObject) {
        try {
            var objExcel;
            objExcel = new ActiveXObject("Excel.Application");
            objExcel.Visible = true;
            objExcel.Workbooks.Open(strLocation, false, [readonly: true|false]);
        }
        catch (e) {
            alert (e.message);
        }
    }
    else {
        alert ("Your browser does not support this.");
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Hi, Couldn't get this to work without installing a bunch of excel components on the server. Trying to avoid this.
This is purely on client side (exception being its an IE only solution). Not sure why you needed anything to install on server. Just curious, what did you do on the server exactly?
The excel document is on the server and is accessible through a url. If client doesn't have active x installed, or doesn't own excel, they still need to be able to download the excel file.
Well, in that case, go with the hyperlink approach. Or, in the else block, you can try opening the excel file itself. Something like: window.open("/server/excelfiles/myexcel.xls")
This is not working in IE 11, I get "Your browser does not support this."
|
1

if you link to the xls file, the user will be asked if he wants to download it (or will download it automatically)... then, depending on his settings, it will open automatically in excel or, what's more likely, it just ended up in his downloads folder and he has to open it manually.

2 Comments

Thanks, but I think this has more to do with the UNC path surrounded by [] brackets. I'm trying to get this to work as it already is working else where.
UNC path? so it's for a intranet?! kinda useful information :)
1

In javascript you cannot access to the client softwares or hardisk (for security reason). You only can trigger the download of the xls file and open it manually

1 Comment

The xls file is on the server. In jQuery i wanted to open up Excel file programmatically, but I am having difficulty b/c the UNC path is incorrect from the clients perspective. I think I'm just going to go the <a href="httlocationonthroughtheserver.xls">Excel File</a>
0

This link is informational and work in opening it up in a browser: http://www.dynamicdrive.com/forums/showthread.php?t=6138.

This link is key for opening the file based on file type: http://www.codingforums.com/showthread.php?t=99465

Notice the rel attribute is set to nofollow , and the target is set to '_blank'.

document.location.rel="nofollow" target='_blank';
document.location.href="index.php?hitCount=1&linkID=" + linkID;

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.