-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (39 loc) · 1.4 KB
/
index.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>
<meta charset="utf-8">
<title>Parse CSV to JSON</title>
<script src="https://fastcdn.org/Papa-Parse/4.1.2/papaparse.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type = "text/javascript" scr="papaparse.js"></script>
<script type = "text/javascript" src="FileSaver.js"></script>
</head>
<body>
<form class="form-inline">
<div class="form-group">
<label for="files">Upload a CSV formatted file:</label>
<input type="file" id="files" class="form-control" accept=".csv" required />
<button type="submit" id="submit" class="btn btn-primary" >Submit</button>
</div>
</form>
<script type="application/javascript">
$(document).ready(function(){
$('#submit').on("click",function(e){
e.preventDefault();
if (!$('#files')[0].files.length){
alert("Please choose at least one file to read the data.");
}
var x = document.getElementById("files");
Papa.parse(x.files[0],{
header: true, complete: function(results)
{
console.log("Parse results:", results.data);
var blob = new Blob([JSON.stringify(results.data)],{type: "application/json"});
saveAs(blob,"download.json");
}
});
});
});
</script>
</body>
</html>