Spaces:
Running
Running
Update index.html
Browse files- index.html +30 -7
index.html
CHANGED
|
@@ -86,14 +86,37 @@
|
|
| 86 |
</div>
|
| 87 |
|
| 88 |
<script>
|
| 89 |
-
//
|
| 90 |
function parseCSV(content) {
|
| 91 |
-
const rows =
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
// Load CSV file
|
|
|
|
| 86 |
</div>
|
| 87 |
|
| 88 |
<script>
|
| 89 |
+
// Improved CSV parsing to handle quoted fields
|
| 90 |
function parseCSV(content) {
|
| 91 |
+
const rows = [];
|
| 92 |
+
let currentRow = [];
|
| 93 |
+
let currentField = '';
|
| 94 |
+
let insideQuotes = false;
|
| 95 |
+
|
| 96 |
+
for (let i = 0; i < content.length; i++) {
|
| 97 |
+
const char = content[i];
|
| 98 |
+
|
| 99 |
+
if (char === '"') {
|
| 100 |
+
insideQuotes = !insideQuotes;
|
| 101 |
+
} else if (char === ',' && !insideQuotes) {
|
| 102 |
+
currentRow.push(currentField.trim());
|
| 103 |
+
currentField = '';
|
| 104 |
+
} else if (char === '\n' && !insideQuotes) {
|
| 105 |
+
currentRow.push(currentField.trim());
|
| 106 |
+
rows.push(currentRow);
|
| 107 |
+
currentRow = [];
|
| 108 |
+
currentField = '';
|
| 109 |
+
} else {
|
| 110 |
+
currentField += char;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Add the last field and row
|
| 115 |
+
if (currentField) currentRow.push(currentField.trim());
|
| 116 |
+
if (currentRow.length > 0) rows.push(currentRow);
|
| 117 |
+
|
| 118 |
+
const headers = rows.shift();
|
| 119 |
+
return { headers, rows };
|
| 120 |
}
|
| 121 |
|
| 122 |
// Load CSV file
|