我正在尝试使用 Angular 打开一个 CSV 文件,以将此 CSV 的内容设置为矩阵并将其发布到交互式网络上



我无法打开CSV,我尝试了几种不同的方法,但被卡住了。如果你能给我一些帮助,谢谢

我创建了angular项目,但当我试图从https服务打开CSV时,它没有打开任何

您可以使用ngx-papaparse来解析csv。

<div class="box-body">
<div class="form-group">
<label for="csv_file">Select File</label>
<input type="file" (change)="onFileSelect($event)" id="csv_file" multiple="false" />
</div>
</div>
onFileSelect(event) {
this.csvContent = event.target.files[0];
const reader: FileReader = new FileReader();
reader.readAsText(this.csvContent);
reader.onload = (e) => {
const csvData = reader.result;
const options = {
complete: (results, file) => {
console.log(results.data); // it will give you the exact data as array
},
skipEmptyLines: true
};
// @ts-ignore
this.papa.parse(csvData, options);
};
}

最新更新