您好,是这样的,在angular-cli中,fileSaver的引用方式有所不同
首先,使用npm install file-saver 安装file-saver包
接下来在app.component.ts中通过import导入saveAs
import { saveAs } from 'file-saver';
之后正常直接调用saveAs方法即可。相关代码可供参考:
- import { Component } from '@angular/core';
- import { saveAs } from 'file-saver';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- title = 'app';
- spread: any;
- workbookInit(args) {
- this.spread = args.spread;
- }
- _click(args:any) {
- var excelIO = new GC.Spread.Excel.IO();
- var json = this.spread.toJSON({includeBindingSource: true});
- var fileName = "test.xlsx";
- excelIO.save(json, function (blob:any) {
- saveAs(blob, fileName);
- }, function (e:any) {
- console.log(e);
- });
- }
- }
复制代码 |