解决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中文乱码

转载于:https://www.cnblogs.com/wuhailong/p/7605288.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值