Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将base64编码字符串解码为xls_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 将base64编码字符串解码为xls

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

我在用户请求获取excel文档时链接了一个JSON响应,响应方式如下

  {
  "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。