回答編集履歴
1
改善したコードを別にアップしたのでこれは不要
answer
CHANGED
@@ -1,33 +1,1 @@
|
|
1
|
-
```javascript
|
2
|
-
|
3
|
-
function readCsv2Table(filepath) {
|
4
|
-
var reader = new FileReader();
|
5
|
-
reader.onload = function(e) {
|
6
|
-
|
1
|
+
新しいコードを別書き込みしました。
|
7
|
-
htmls.push("<table>");
|
8
|
-
$(e.target.result.split(/¥r¥n|¥r|¥n/)).each(function(y, line) {
|
9
|
-
if (line == "") return;
|
10
|
-
htmls.push("<tr>");
|
11
|
-
if (y == 0) {
|
12
|
-
$(line.split(/,/)).each(function(x, o) {
|
13
|
-
htmls.push("<th>" + this + "</tr>");
|
14
|
-
});
|
15
|
-
} else {
|
16
|
-
$(line.split(/,/)).each(function(x,o) {
|
17
|
-
htmls.push("<td>" + this + "</td>");
|
18
|
-
});
|
19
|
-
}
|
20
|
-
htmls.push("</tr>");
|
21
|
-
});
|
22
|
-
$("#result").html(htmls.join(""));
|
23
|
-
}
|
24
|
-
reader.readAsText(filepath, "shift-jis");
|
25
|
-
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
```
|
31
|
-
|
32
|
-
こんな感じ。
|
33
|
-
result id を持つ、div タグ、引数のfilepath は <input type=file /> で取得したパスを指定する。
|