【angular-实践】导入/导出excel

龙浩博
2023-12-01

安装依赖

npm install @notadd/ngx-xlsx -S
npm install xlsx -S
npm install file-saver -S

使用步骤

  • 添加NgxXLSXModule到你的Angular Module
  import { NgxXLSXModule } from '@notadd/ngx-xlsx';

  @NgModule({
    imports: [
        ...
        NgxXLSXModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
  })
  export class AppModule { }
  • 在你的component中引入 NgxXLSXService
import { NgxXLSXService } from '@notadd/ngx-xlsx';

constructor(
    private xlsSwevice: NgxXLSXService
  ) {
  const json = [
      {
        t: "oo",
        t2: "t2"
      }
    ]
    // 导出excel
    this.xlsSwevice.exportAsExcelFile(json)
  }

参考

 类似资料: