CSV to html table

CSV to html table

本文关键字:table html to CSV      更新时间:2023-09-26

在此中,只会打开一个CSV文件。我想打开多个 CSV 文件并在 HTML 表中编辑它们。请帮忙。

$(function() {
    Papa.parse("abc.csv", {
        download: true,
        complete: function(results) {
            console.log("Remote file parsed!", results.data);
            $.each(results.data, function(i, el) {
                var row = $("<tr/>");
                row.append($("<td/>").text(i));
                $.each(el, function(j, cell) {
                    if (cell !== "")
                        row.append($("<td/>").text(cell));
                });
                $("#results tbody").append(row);
            });
        }
    });
});     

你必须做一个循环,这里我们有一个你的csv文件数组:

var csv_array = ["abc.csv","def.csv","ghi.csv"];
    $(function() {
        $(csv_array).each(function(){
            Papa.parse(this.toString(), {
                download: true,
                complete: function(results) {
                    console.log("Remote file parsed!", results.data);
                    $.each(results.data, function(i, el) {
                        var row = $("<tr/>");
                        row.append($("<td/>").text(i));
                        $.each(el, function(j, cell) {
                            if (cell !== "")
                                row.append($("<td/>").text(cell));
                        });
                        $("#results tbody").append(row);
                    });
                }
            });
        })
    });