使用指定的charset下载BLOB内容 [英] Download BLOB content using specified charset

查看:540
本文介绍了使用指定的charset下载BLOB内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能真的改变Blob charset吗?我正在尝试几个小时,但它不起作用。 查看此

Is possible to change the Blob charset really? I'm trying it for hours but it doesn't workds. See this.

jQuery("#download").click(function() {
    var csv_content = jQuery("#csv").val(),
        download = document.createElement("a"),
        blob = new Blob([csv_content], { type: "text/csv;charset=ISO-8859-1" });

    download.href = window.URL.createObjectURL(blob);
    download.download = "test.csv";

    var event = document.createEvent("MouseEvents");
    event.initMouseEvent(
        "click", true, false, window, 0, 0, 0, 0, 0
        , false, false, false, false, 0, null
    );
    download.dispatchEvent(event);    
});

我需要导出一个CSV才能在Excel上打开,但它总是以UTF-8和Excel保存无法处理它。

I need export a CSV to open on Excel, but it always is save with UTF-8 and Excel can't handle it.

推荐答案

我发现之前的解决方案。

事实上,charset的变化尚未得到解决。但是,我发送了UTF-8标头用于下载过程,Excel能够正确理解文件格式。 感谢ErikTöyrä的回复

The change of charset has not been resolved, in fact. However, I sent the UTF-8 header for the download process and Excel was able to understand the file format correctly. Thanks to this response of Erik Töyrä.

blob = new Blob(["\ufeff", csv_content]);

这篇关于使用指定的charset下载BLOB内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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