Created
May 4, 2024 21:23
-
-
Save glenacota/410522bf8b9f18dde376dba46a842942 to your computer and use it in GitHub Desktop.
convert SFIA xlsx to JSON
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Convert SFIA xlsx to JSON</title> | |
<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js"></script> | |
<style>pre { background-color: bisque; font-family: monospace; display: inline-block; }</style> | |
</head> | |
<body> | |
<input class="form-input" type="file" id="input" accept=".xls,.xlsx"><br/> | |
<pre id="output"></pre> | |
</body> | |
<script lang="javascript"> | |
function processRow(rowObject) { | |
delete rowObject.guidance | |
rowObject.tags = rowObject.tags.split(/,|and/) | |
.map(tag => tag.trim().toLowerCase()) | |
return rowObject | |
} | |
document.getElementById('input').addEventListener("change", (event) => { | |
let selectedFile = event.target.files[0]; | |
let fileReader = new FileReader(); | |
fileReader.readAsBinaryString(selectedFile); | |
fileReader.onload = (event)=>{ | |
let data = event.target.result; | |
let workbook = XLSX.read(data, {type: "binary"}); | |
const headers = ['skill', 'category', 'tags', 'description', 'guidance', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6', 'level7'] | |
let rowObjects = XLSX.utils.sheet_to_json(workbook.Sheets['Skills'] ,{ header: headers, defval: "", range: "J2:U500", blankrows: false }) | |
let output = rowObjects.map(processRow) | |
document.getElementById("output").innerHTML = JSON.stringify(output, undefined, 4); | |
} | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment