From 7ee3266ab38f030d73639d246bfa175fa553e3b0 Mon Sep 17 00:00:00 2001 From: Sini Date: Mon, 19 Apr 2021 12:04:58 +0000 Subject: [PATCH] xlsx to json conversion with console output --- public/js/search.js | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/public/js/search.js b/public/js/search.js index faaff1a..eb3ea00 100644 --- a/public/js/search.js +++ b/public/js/search.js @@ -59,6 +59,55 @@ var stuff_paper = [] // } // // stuff.forEach(addcontent()); // }); + + + // + // begining of xlsx to json coversion +// + +/* set up XMLHttpRequest */ +var url = "./content/CitationSheet.xlsx"; +var xmlHttpRequest = new XMLHttpRequest(); +xmlHttpRequest.open("GET", url, true); +xmlHttpRequest.responseType = "arraybuffer"; + +xmlHttpRequest.onload = function(e) { + var arraybuffer = xmlHttpRequest.response; + + /* convert data to binary string */ + var data = new Uint8Array(arraybuffer); + var arr = new Array(); + for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]); + var bstr = arr.join(""); + + /* Call XLSX */ + var workbook = XLSX.read(bstr, { + type: "binary" + }); + + /* DO SOMETHING WITH workbook HERE */ + var first_sheet_name = workbook.SheetNames[0]; + /* Get worksheet */ + var worksheet = workbook.Sheets[first_sheet_name]; + + var jsonOutput = XLSX.utils.sheet_to_json(worksheet); + console.log(jsonOutput); + + // Papa.parse(jsonOutput, { + // download: true, + // header : false, + // complete: function(results) { + // console.log(results.data); + // } + // }); + +} +xmlHttpRequest.send(); + + // + // ending of xlsx to json coversion +// + $(document).ready(function(){ $.getJSON("./content/content.json", function(result){ stuff = result; @@ -178,4 +227,4 @@ input.addEventListener("keyup", function(event) { document.getElementById("search-button_paper").click(); } -}); \ No newline at end of file +}); -- GitLab