Javascript 将base64编码字符串解码为xls
我在用户请求获取excel文档时链接了一个JSON响应,响应方式如下Javascript 将base64编码字符串解码为xls,javascript,angular,typescript,Javascript,Angular,Typescript,我在用户请求获取excel文档时链接了一个JSON响应,响应方式如下 { "format": // file extn ----only xls "docTitle": //file name "document" :// base 64 encoded data } 我试图通过使用atob()函数解码文档密钥来处理前端的API downloadTemplate() { this.fetchData.fetchDownloadTemplate().subscribe
{
"format": // file extn ----only xls
"docTitle": //file name
"document" :// base 64 encoded data
}
我试图通过使用atob()函数解码文档密钥来处理前端的API
downloadTemplate() {
this.fetchData.fetchDownloadTemplate().subscribe(
res => {
let docString = atob(res.document);
let format = res.format;
let fileName = res.docTitle;
let file = new Blob([docString], {type: "text/xls"});
let url = URL.createObjectURL(file);
let dwldLink = document.getElementById('template_link');
dwldLink.setAttribute("href", url);
dwldLink.setAttribute("download", fileName);
document.body.appendChild(dwldLink);
dwldLink.click();
},
err => {
console.log(err.responseJSON.message);
})
}
但是数据被破坏了,在做一些研究时,我知道atob()使用ASCII字符集进行解码,而我使用字符集UTF-8进行编码
您能推荐任何其他方法来解码typescript中使用UTF-8字符集的数据吗,因为我正在处理的angular(v4+)项目在使用JS验证器时出错。在搜索支持Unicode到二进制转换的合适模块时,我遇到了 Base64.decode()支持utob decryption
该模块支持angular(v4+),还为Typescript(2)添加了依赖项。在搜索支持Unicode到二进制转换的合适模块时,我遇到了 Base64.decode()支持utob decryption
该模块支持angular(v4+),还为Typescript(2)添加依赖项。angular js有一个库,不确定它是否适用于angular 2。angular js有一个库,不确定它是否适用于angular 2。