7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript でcsvをtableに変換する

Last updated at Posted at 2016-08-01
var table = csv2table(csv);


    function csv2table(text) {

        var rows = text.split("\n");
        var table = document.createElement("table");

        for ( var i = 0; i < rows.length; i++ ) {
            var tr = document.createElement("tr");
            var tds = rows[i].split(",");
            for ( var j = 0; j < tds.length; j++ ) {
               var td = document.createElement(i == 0 ? "th" : "td");
               td.innerHTML = tds[j];
               tr.appendChild(td);
            }
            table.appendChild(tr);
        }

        return table.innerHTML;
    }
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?