下载 base 64 到 xls

download base 64 to xls

Base 64数据如下。

UEsDBBQAAAAIAIlimE8HQU1igQAAALEAAAAQAAAAZG9jUHJvcHMvYXBwLnhtbE2OPQsCMRBE/8px\nvbdBwUJiQNBSsLIPexsvkGRDskJ+vjnBj24ebxhG3wpnKuKpDi2GVI/jIpIPABUXirZOXaduHJdo\npWN5ADvnkc6Mz0hJYKvUHqgJpZnmTf4Ojkafcg4erXhO5uqxcGUnw6UhBQ3/cm3eqdQ17yb1lh/W\n8DtpXlBLAwQUAAAACACJYphPJoGuS+4AAAArAgAAEQAAAGRvY1Byb3BzL2NvcmUueG1szZLBSsQw\nEIZfRXJvp8mKaOjmonhSEFxQvIVkdjds04RkpN23N627XUQfwGNm/nzzDUxrojQh4UsKERM5zFej\n7/osTVyzPVGUANns0etcl0RfmtuQvKbyTDuI2hz0DkE0zQ14JG01aZiAVVyITLXWSJNQU0gnvDUL\nPn6mboZZA9ihx54y8JoDU9PEeBy7Fi6ACUaYfP4uoF2Ic/VP7NwBdkqO2S2pYRjqYTXnyg4c3p+f\nXud1K9dn0r3B8is7SceIa3ae/La6f9g8MiUafldxUYnrDRdSNJLffkyuP/wuwj5Yt3X/2PgsqFr4\ndRfqC1BLAwQUAAAACACJYphPmVycIxAGAACcJwAAEwAAAHhsL3RoZW1lL3RoZW1lMS54bWztWltz\n2jgUfu+v0Hhn9m0LxjaBtrQTc2l227SZhO1OH4URWI1seWSRhH+/RzYQy5YN7ZJNups8BCzp+85F\nR+foOHnz7i5i6IaIlPJ4YNkv29a7ty/e4FcyJBFBMBmnr/DACqVMXrVaaQDDOH3JExLD3IKLCEt4\nFMvWXOBbGi8j1uq0291WhGlsoRhHZGB9XixoQNBUUVpvXyC05R8z+BXLVI1lowETV0EmuYi08vls\nxfza3j5lz+k6HTKBbjAbWCB/zm+n5E5aiOFUwsTAamc/VmvH0dJIgILJfZQFukn2o9MVCDINOzqd\nWM52fPbE7Z+Mytp0NG0a4OPxeDi2y9KLcBwE4FG7nsKd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AAIAIli\nmE9lkHmSGQEAAM8DAAATAAAAAAAAAAAAAACAAUQSAABbQ29udGVudF9UeXBlc10ueG1sUEsFBgAA\nAAAJAAkAPgIAAI4TAAAAAA==\n

我想在 angular 6.

中使用打字稿单击按钮将其下载为 .xls 文件

您可以使用file-saver

import * as FileSaver from 'file-saver';

saveFile() {
    saveAs(this.base64data, `filename.xls`)
}

您可以通过 DomSanitizer 清理此字符串并提供 data:application/octet-stream;base64 作为类型。

为了清理字符串,我使用了自定义管道 safe。请查看 stackblitz。

Demo

HTML

<a [href]="'data:application/octet-stream;base64,' + data | safe" download="excel.xls">Download</a>

safe.pipe.ts

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Pipe({
  name: 'safe'
})
export class SafePipe implements PipeTransform {

  constructor(private sanitizer: DomSanitizer) { }

  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
}