Created
February 7, 2014 06:53
-
-
Save tigawa/8858345 to your computer and use it in GitHub Desktop.
CSVファイルをJavaScriptから読込み方法 (ファイルを指定すると、2次元配列で結果はを返す。)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function csv2Array(filePath) { //csvファイルノ相対パスor絶対パス | |
var csvData = new Array(); | |
var data = new XMLHttpRequest(); | |
data.open("GET", filePath, false); //true:非同期,false:同期 | |
data.send(null); | |
var LF = String.fromCharCode(10); //改行コード | |
var lines = data.responseText.split(LF); | |
for (var i = 0; i < lines.length;++i) { | |
var cells = lines[i].split(","); | |
if( cells.length != 1 ) { | |
csvData.push(cells); | |
} | |
} | |
return csvData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment