views:

740

answers:

6

I'm working on a web app (ASP.NET) that has some features that require Microsoft Excel installed on the client. I'd like to disable those features if Excel is not present.

Windows/IE/Excel only solutions are fine. This is not a multi-browser, multi-OS web app.

Any clever JavaScript out there to accomplish this?

+6  A: 

No.

You're not allowed to dive into the client machine deep enough to figure out that part. The best you can do is to either assume it is installed, and ponder hard about what happens if it is not, or just ask the user.

Lasse V. Karlsen
+2  A: 

You can do something like this, but you'll get all kinds of security warnings:

<script>
var excelInstalled;
try 
{
    var excel = new ActiveXObject("Excel.Application");
    excelInstalled = true;
}
catch(e)
{
    excelInstalled = false;
}
alert("excelInstalled: " + excelInstalled);
</script>
RedFilter
Thanks. I'll give this a try, I'm curious about the security warnings.
subjective-c
+1  A: 

Why Excel? What if I have OpenOffice.org instead?

Just warn the user what you're going to send them, mark the link with "Excel file", and let him decide.

bart
If you have OpenOffice.org installed you wouldn't be using this web app. I'll edit the question to better reflect Windows/IE/Excel requirement only.
subjective-c
A: 

you can not access client information outside of the web browser context, using standard technologies. but I see one of answers is using some ActivX object to detect Excel. anyway these kinds of technologies work only on Internet Explorer on windows. what about Mac? what about other browsers like opera or firefox or chrome on windows? I think it is better to let the user inform you about this. just ask the user if she has excel installed or not:

var isExcel = window.confirm('dear user if you have Microsoft Excel installed please click on ok, otherwise click on cancel. thank you.');
farzad
A: 

This is bad idea at start. What ever you are trying to do - reconsider.

If you still insist:

Try to crete ActiveXObject for Excel and then for OpenOffice. If it fails, redirect to NoExcel.html or send XMLRequest to server.
Also, you can try to find out via JavaScritp if there is XLS file extension handler. And last, you can install your ActiveX which checks if Excel is installed.

This is for windows. No idea for mac, linux, mobile... You can bet that any way you make it work will stop working with next hotfix.

dmajkic
+1  A: 
function hasOfficePlugin() {
var toCheckExt = ['', '12', '13', '14', '15'], i, n, mt;
    for (i = 0, n = toCheckExt.length; i < n; i++) {
        mt = navigator.mimeTypes['application/x-msoffice' + toCheckExt[i]];
        if (mt && mt.enabledPlugin && mt.enabledPlugin.name) {
            return true;
        }
    }
    return false;
}

I've tested the above with Office 11 (2003), and Office 12 (2007), and it seems to work well in Firefox, Safari, Chrome, and Opera. Though it doesn't work in IE, because the navigator.mimeTypes objects in IE is always empty.

It's checking for the existence of an MS Office plugin. I don't know much about this plugin - quite possibly it's not always installed with office... But I think that, if the above returns true, it's a pretty strong signal that Excel is installed. Course it's probably of limited use since it doesn't work in IE, but maybe you can do something with it...

MB