JS使用Blob导出csv文件中文乱码解决方案

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_26963495/article/details/84974528

在数据前面加上字符串"\ufeff"即可。示例:

exportStatisticData: function (type) {
        let data = '';
        let filename = '';
        if (type === 'LABEL') {
          data = this.generateCSV(this.statisticData.label);
          filename = '任务标注统计_' + this.job.jobName;
        } else if (type === 'INSPECT') {
          data = this.generateCSV(this.statisticData.inspect);
          filename = '任务质检统计_' + this.job.jobName;
        }
        data = "\ufeff" + data;
        let blob = new Blob([data], { type: 'text/csv,charset=UTF-8'});
        let url = URL.createObjectURL(blob);
        let a = document.createElement("a");
        a.download = filename + ".csv";
        a.href = url;
        a.click();
      }

 

展开阅读全文

没有更多推荐了,返回首页