js前端base64转word并下载

2020-08-24  本文已影响0人  爱代码的派派星
代码如下
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)
上一篇下一篇

猜你喜欢

热点阅读