前言:
我选用的是 ngx-csv
npm install --save ngx-csv
例子:
<button mat-raised-button color="primary"
(click)="download()">{{ 'LICENSE_MANAGE.FORM.UPLOAD' | translate }}</button>
import { ngxCsv } from 'ngx-csv/ngx-csv';
download(){
let langs = this.translate.translations[this.translate.currentLang].LICENSE_MANAGE.TABLE;
let options = {
fieldSeparator: ',',
quoteStrings: '"',
decimalseparator: '.',
showLabels: true,
// showTitle: true,
// title: 'Your title',
useBom: true,
noDownload: false,
headers: ['id', langs.LICENSE_KEY, langs.LICENSE_DESC]
};
let data = [
{
id: '1',
LicenseKey: '111',
LicenseDescription: 'test1'
},
{
id: '2',
LicenseKey: '222',
LicenseDescription: 'test2'
},
{
id: '3',
LicenseKey: '333',
LicenseDescription: 'test3'
},
];
new ngxCsv(data, '上传模版',options);
}