I needed to export data of a table to Excel. I got a solution as below:
http://jsfiddle.net/jquerybyexample/xhYcD/
In the above example, it allows you to generate .xls file when Microsoft Excel is installed on the system but I have OpenOffice installed on my system, so when I add the line
window.open('data:application/vnd.oasis.opendocument.spreadsheet,' + $('#dvData').html());
instead of
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
then it generates the .ods file.
I need to determine whether Excel or Open Office is installed so that I can put the condition for the above two lines using jQuery or JavaScript.
EDIT
Can I put back to back the two conditions, is that a harm?
$("#btnExport").click(function(e) {
window.open('data:application/vnd.oasis.opendocument.spreadsheet,' + $('#dvData').html());
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
e.preventDefault();
});
ANOTHER EDIT
Just tried this solution on IE8, it doesn't work. Any other alternatives for this solution or this can be fixed to work on IE?