簡體   English   中英

我正在嘗試使用 Angular 打開 CSV 文件,以將此 CSV 的內容設置為矩陣並將其發布在交互式 Z21567A5EC933EEB66

[英]I'm trying to open a CSV file with Angular to set the content of this CSV to a matrix and publish it on an interactive web

我無法打開 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);
    };
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM