如何使用jquery确定系统上是否安装了Microsoft Excel或Open Office [英] How to determine whether Microsoft Excel or Open Office is installed on the system using jquery

查看:103
本文介绍了如何使用jquery确定系统上是否安装了Microsoft Excel或Open Office的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将表的数据导出到Excel.我得到了如下解决方案:

I needed to export data of a table to Excel. I got a solution as below:

http://jsfiddle.net/jquerybyexample/xhYcD/

在上面的示例中,当系统上安装了Microsoft Excel但我的系统上安装了OpenOffice时,它允许您生成xls文件,因此当我添加行

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

代替

 window.open('data:application/vnd.ms-excel,' + $('#dvData').html());

然后生成.ods文件.

then it generates the .ods file.

我需要确定是否安装了Excel或Open Office,以便可以使用jQuery或Javascript来设置上述两行的条件.

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.

我可以退回这两个条件吗,这是有害的吗?

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();
});

另一项 刚刚在IE8上尝试过此解决方案,它不起作用.此解决方案是否有其他替代方案,或者可以固定为在IE上运行?

ANOTHER 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?

推荐答案

我发布了一个问题,即我是您的预期答案.希望对您有所帮助. 将HTML表导出为Java脚本中的EXCEL

i have posted question that me be your expected answer.hope this help you. Export HTML Table to EXCEL in Java script

function downloadsalesreport () {

            var cache = {};

            this.tmpl = function tmpl(str, data) {
                // Figure out if we're getting a template, or if we need to
                // load the template - and be sure to cache the result.
                var fn = !/\W/.test(str) ?
                  cache[str] = cache[str] ||
                    tmpl(document.getElementById(str).innerHTML) :

                  // Generate a reusable function that will serve as a template
                  // generator (and which will be cached).
                  new Function("obj",
                    "var p=[],print=function(){p.push.apply(p,arguments);};" +

                    // Introduce the data as local variables using with(){}
                    "with(obj){p.push('" +

                    // Convert the template into pure JavaScript
                    str.replace(/[\r\t\n]/g, " ")
                          .split("{{").join("\t")
                          .replace(/((^|}})[^\t]*)'/g, "$1\r")
                          .replace(/\t=(.*?)}}/g, "',$1,'")
                          .split("\t").join("');")
                          .split("}}").join("p.push('")
                          .split("\r").join("\\'")
                          + "');}return p.join('');");

                // Provide some basic currying to the user
                return data ? fn(data) : fn;
            };
 var tableToExcel = (function () {
 var uri = 'data:application/vnd.ms-excel;base64,',
                    template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{{=worksheet}}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>{{for(var i=0; i<tables.length;i++){ }}<table>{{=tables[i]}}</table>{{ } }}</body></html>',
                base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
                format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
                return function (tableList, name) {
                    if (!tableList.length > 0 && !tableList[0].nodeType) table = document.getElementById("#tablesalesentry")
                    var tables = [];
                    for (var i = 0; i < tableList.length; i++) { tables.push(tableList[i].innerHTML); }
                    var ctx = { worksheet: name || 'Worksheet', tables: tables };
                    window.location.href = uri + base64(tmpl(template, ctx))
                }
            })();

            tableToExcel(document.getElementsByTagName("table"), "one");

        }

这篇关于如何使用jquery确定系统上是否安装了Microsoft Excel或Open Office的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆