【发布时间】:2017-12-21 15:36:24
【问题描述】:
我正在制作一个 Angular4 我有一个按钮,可以将数据转换为带有标题的 csv 文件。 现在我想反过来做,我想上传一个 csv 文件。 因此,为了进行测试,我制作了一个对象并从中制作了一个 csv 文件,然后我想单击一个按钮并上传该文件并获得相同的结果。
我找到了一个用于导出 csv 的 Angular 模块,但我找不到相反的模块。有人可以帮我吗?
这是我的代码:
test.ts
import { Component, OnInit} from '@angular/core';
import { Angular2Csv } from 'angular2-csv/Angular2-csv';
import {Unit} from "../../../_shared/unit";
@Component({
moduleId: module.id,
templateUrl: 'test.component.html',
styleUrls: ['./test.css']
})
export class TestComponent implements OnInit {
ngOnInit() {}
public export() {
// Unit (id,name,description)
var data = [new Unit(1,"Unit1","This is unit 1!")];
var options = {
fieldSeparator: ';',
quoteStrings: '"',
decimalseparator: ',',
showLabels: true,
useBom: true
};
new Angular2Csv(data, "data", options);
}
public import(){}
}
test.html
<button (click)="export()">Download CSV</button>
<button (click)="import()">Upload CSV</button>
【问题讨论】:
标签: html json angular csv typescript