zoukankan      html  css  js  c++  java
  • 解决js导出csv中文乱码

    function doCSV(json) {
                // 1) find the primary array to iterate over
                // 2) for each item in that array, recursively flatten it into a tabular object
                // 3) turn that tabular object into a CSV row using jquery-csv
                var inArray = arrayFrom(json);
    
                var outArray = [];
                for (var row in inArray)
                    outArray[outArray.length] = parse_object(inArray[row]);
    
                $("span.rows.count").text("" + outArray.length);
    
                var csv = $.csv.fromObjects(outArray);
                // excerpt and render first few rows
                renderCSV(outArray.slice(0, excerptRows));
                showCSV(true);
    
                // if there's more we're not showing, add a link to show all
                if (outArray.length > excerptRows)
                    $(".show-render-all").show();
    
                // show raw data if people really want it
                $(".csv textarea").val(csv);
    
                // download link to entire CSV as data
                // thanks to https://jsfiddle.net/terryyounghk/KPEGU/
                // and https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
                //var uri = "data:text/csv;charset=utf-8," + encodeURIComponent(csv);
                var uri = "data:text/csv;charset=utf-8,uFEFF" + encodeURI(csv);
                $(".csv a.download").attr("href", uri);
            }
    

      解决js导出csv中文乱码

  • 相关阅读:
    3. What’s New in Spring Security 4.2 spring security 4.2的新功能
    2. Introduction介绍
    1. Getting Started入门
    32. CAS Authentication
    Java序列化
    hive优化--数据倾斜优化
    hive优化之——控制hive任务中的map数和reduce数
    maven中引入jstl
    redis位操作
    Windows单机安装hadoop
  • 原文地址:https://www.cnblogs.com/wuhailong/p/7605288.html
Copyright © 2011-2022 走看看