【问题标题】:Dojo DataGrid export to excelDojo DataGrid 导出到 excel
【发布时间】:2012-08-16 09:06:45
【问题描述】:

我使用了数据网格的导出器插件,并获得了 CSV 格式的网格数据。 但我想让这些数据以 excel 格式下载。一种解决方案是我可以向服务器发送一个 ajax 请求并发送回 excel。

只是想知道是否有一种方法可以在不访问服务器的情况下创建和下载此 excel。

我现在的导出代码是:

        function exportAll(){
            dijit.byId("grid").exportGrid("csv", function(str){
                alert('Data to be exported',str);
            });
        };

【问题讨论】:

    标签: dojo dojox.grid


    【解决方案1】:

    Exporting a dojo datagrid to a csv file

    您无法通过 javascript 打开 excel,因此它需要是 GET 下载请求。

    使用xhrPoststr发送到服务器,放入temp-file那里,打印temp-url并在xhrPost成功回调函数中调用window.open("./" + responseText, "_new");。也可以使用io.iframe 传输该帖子显示的答案之一。

       function exportAll(){
            dijit.byId("grid").exportGrid("csv", function(str){
                dojo.xhrPost({
                    url: '/putExportData.php',
                    load: function(tempUrl) {
                        window.open(tempUrl, "_new");
                    }
                });
            });
        };
    

    【讨论】:

    • 我认为 JavaScript 的限制/安全性比 Dojo 有任何问题。
    • 它是.. 如果你想在 IE 中支持它,你可以进入 ActiveX 组件。它具有写入磁盘的能力 - 而 JS 被拒绝此功能(除了 session/cookie 存储 ofc)
    猜你喜欢
    • 2010-09-21
    • 2013-11-08
    • 2010-09-23
    • 2015-11-22
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    相关资源
    最近更新 更多