js前端base64转word并下载

代码如下
var raw = window.atob(ba);
var uInt8Array = new Uint8Array(raw.length);
for (var i = 0; i < raw.length; i++) {
  uInt8Array[i] = raw.charCodeAt(i);
}

const link = document.createElement("a");
const blob = new Blob([uInt8Array],{
  // type: 'application/vnd.ms-excel'
  type: 'application/msword'
})

link.style.display = 'none';
link.href = URL.createObjectURL(blob);
//link.setAttribute('download','对比结果_'+$scope.你的变量+'.xls');
link.setAttribute('download','对比结果');

document.body.appendChild(link)
link.click()

document.body.removeChild(link)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。