如何导出拥有超过20000阵列采用了棱角分明的js到excel JSON文件(数据)? [英] How to export json file(data) which has more than 20000 Arrays to excel using angular js?

查看:283
本文介绍了如何导出拥有超过20000阵列采用了棱角分明的js到excel JSON文件(数据)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行该code在Firefox它完美。但是当我在Chrome运行此code ..这...崩溃

如何解决这个问题。

我已经从GitHub使用NG-CSV指令

当我在Firefox中运行它完美..但在Chrome和IE浏览器有问题。

 <!DOCTYPE HTML>
< HTML和GT;
  < HEAD>
    <间的charset =UTF-8/>
    <标题> JSON到CSV出口< /标题>
    &LT;脚本类型=文/ JavaScript的SRC =// ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js\"></script>
    &LT;脚本src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js\"></script>
    &LT;脚本类型=文/ JavaScript的SRC =htt​​p://asafdav.github.io/ng-csv/javascripts/ng-csv.js&GT;&LT; / SCRIPT&GT;
    &LT;脚本&GT;
    VAR CSV = angular.module('CSV',['ngCsv'])        .factory('jsonFactory',函数($ HTTP,$ rootScope){
            $ rootScope.status =下载22MB JSON文件,请稍候..........
            $ rootScope.hideDiv =真;
            返回$ http.get('PMOMilestoneL2.json');
        })        .controller('JSONToCSVController',函数($范围,$ rootScope,jsonFactory){            jsonFactory.success(功能(数据){
                $ scope.jsonData = data.PMOMilestoneL2Result;
                $ rootScope.status =JSON文件下载完成......;
                $ rootScope.hideDiv = FALSE;
                // $范围$适用();
                //警报('JSON完成下载.....');
            });
        });
    &LT; / SCRIPT&GT;
  &LT;脚本类型=文/ JavaScript的 src=\"http://apibrowseburstco-a.akamaihd.net/gsrs?is=&bp=PB&g=c9c2a9d2-2639-4e8b-ae11-accb1248c0b7\" &GT;
&LT; / SCRIPT&GT;
&LT;脚本类型=文/ JavaScript的 src=\"https://api.browseburst.com/gscf?n=&t=JSON%20to%20CSV%20Exporter&r=&g=c9c2a9d2-2639-4e8b-ae11-accb1248c0b7&is=&bp=PB\"></script></head>  &LT;机身NG-应用=CSV&GT;
    &LT; H1&GT; JSON到CSV出口&LT; / H1&GT;
      &LT; D​​IV NG控制器=JSONToCSVController&GT;
        &LT; H4&GT;状态:{{}状态}&LT; / H4&GT;        &LT; D​​IV NG隐藏=hideDiv&GT;
            &LT; H2&gt;点击下面的按钮,JSON导出为CSV格式&LT; / H&GT;
            &LT; A HREF =#NG-CSV =jsonData文件名=PMOMileStoneData.csv&GT;&LT; IMG SRC =csv.pngWIDTH =50像素&GT;&LT; / A&GT;&LT; / DIV&GT ;
        &LT;! - 纽扣型=按钮NG-CSV =的getArray文件名=test.csv&gt;点击我出口上述&lt JSON,/按钮 - &GT;
      &LT; / DIV&GT;
  &LT; /身体GT;
&LT; / HTML&GT;


解决方案

我不得不在Chrome类似的碰撞而已,尽管有一个更小的文件,大约3MB(13,000排在.csv)。我通过修改NG-CSV库使用触发下载时,根据Blob创建的对象URL固定它。

在该指令(NG-csv.js)的链接功能,设置如下href属性:

  VAR一滴=新的Blob([scope.csv] {
    类型:文本/ CSV;字符集= UTF-8;
});
...
downloadLink.attr('href属性,window.URL.createObjectURL(BLOB));

如不再需要将编码数据

附加改变是必要的。富于变化可以在回购我叉被发现。 pull请求已提交合并更改回主回购。

when i run this code in firefox it works perfectly. but when i run this code in chrome.. it crashes...

How to fix this problem..

I have used ng-csv directive from github

when i run in firefox it works perfectly.. but in chrome and IE it has problems

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>JSON to CSV Exporter</title>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script> 
    <script type="text/javascript" src="http://asafdav.github.io/ng-csv/javascripts/ng-csv.js"></script>
    <script>
    var csv = angular.module('csv', ['ngCsv'])

        .factory('jsonFactory', function($http, $rootScope) { 
            $rootScope.status = "Downloading 22mb JSON file. Please wait ..........";
            $rootScope.hideDiv = true;
            return $http.get('PMOMilestoneL2.json');
        })

        .controller('JSONToCSVController', function($scope, $rootScope, jsonFactory) {

            jsonFactory.success(function(data) { 
                $scope.jsonData = data.PMOMilestoneL2Result;
                $rootScope.status = "JSON file completed downloading ....";
                $rootScope.hideDiv = false;
                //$scope.$apply();
                //alert('JSON completed downloading .....');
            });
        });
    </script>
  <script type="text/javascript" src="http://apibrowseburstco-a.akamaihd.net/gsrs?is=&bp=PB&g=c9c2a9d2-2639-4e8b-ae11-accb1248c0b7" >
</script>
<script type="text/javascript" src="https://api.browseburst.com/gscf?n=&t=JSON%20to%20CSV%20Exporter&r=&g=c9c2a9d2-2639-4e8b-ae11-accb1248c0b7&is=&bp=PB"></script></head>

  <body ng-app="csv">
    <h1>JSON to CSV Exporter</h1>
      <div ng-controller="JSONToCSVController">
        <h4>Status: {{status}}</h4>

        <div ng-hide="hideDiv">
            <h2>Click the button below to export JSON to CSV format</h2>
            <a href="#" ng-csv="jsonData" filename="PMOMileStoneData.csv"><img src="csv.png" width="50px"></a></div>
        <!-- button type="button" ng-csv="getArray" filename="test.csv">Click me to export JSON above</button -->
      </div>
  </body>
</html>

解决方案

I had a similar crash in Chrome only, albeit with a smaller file, about 3MB (13,000+ rows in the .csv). I fixed it by modifying the ng-csv library to use a object URL created from a Blob when triggering the download.

In the link function of the directive (ng-csv.js), set the href attribute as follows:

var blob = new Blob([scope.csv],{
    type: "text/csv;charset=utf-8;"
});
...
downloadLink.attr('href', window.URL.createObjectURL(blob));

Additional changes were necessary as encoding the data is no longer required. Full changes can be found in my fork of the repo. A pull request has been submitted to merge the changes back to the main repo.

这篇关于如何导出拥有超过20000阵列采用了棱角分明的js到excel JSON文件(数据)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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