-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.html
66 lines (59 loc) · 1.99 KB
/
gui.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<title>CSV Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
padding: 5px;
}
</style>
</head>
<body>
<h1>CSV Viewer</h1>
<input type="file" id="csvFile" name="file" accept=".csv">
<div id="output"></div>
<script>
document.getElementById('csvFile').addEventListener('change', function(evt) {
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
console.log(results.data);
displayData(results.data);
}
});
});
function displayData(data) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = ''; // clear the output div
var table = document.createElement('table');
// create table header from keys of first object
var firstRow = data[0];
var tr = document.createElement('tr');
for (var key in firstRow) {
var th = document.createElement('th');
th.textContent = key;
tr.appendChild(th);
}
table.appendChild(tr);
// create table rows
data.forEach(function(row) {
var tr = document.createElement('tr');
for (var key in row) {
var td = document.createElement('td');
td.textContent = row[key];
tr.appendChild(td);
}
table.appendChild(tr);
});
outputDiv.appendChild(table);
}
</script>
</body>
</html>