Commit 476f9667 authored by Joe T.S.'s avatar Joe T.S. :ping_pong:
Browse files

Merge branch 'sabo.sini-master-patch-44308' into 'master'

ExcelToJson Update

See merge request ugl/website!4
No related merge requests found
Showing with 102 additions and 1 deletion
+102 -1
......@@ -59,6 +59,107 @@ var stuff_paper = []
// }
// // stuff.forEach(addcontent());
// });
//
// begining of xlsx to json coversion
//
var jsonContent = [];
/* 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);
for (i=0; i < jsonOutput.length; i++){
var item = {
"item": {"title": "",
"project": "",
"authors": [],
"imageLink":"",
"keywords":"",
"journal": {"name":"journal","volume":"","year":"","pages":""},
"DOI":""},
"links": {"pdf":"","url": "","demo": ""}
}
var authors = jsonOutput[i].Authors.replace("and " ,"").trim().split(",");
item["item"].title = jsonOutput[i].Titel;
item["item"].project = jsonOutput[i].Project;
for (j=0; j < authors.length; j++){
var author = {
"firstName": "",
"lastName": ""
}
if (authors[j].trim().split(" ").length == 1){
author["firstName"] = authors[j].trim().split(".")[0];
author["lastName"] = authors[j].trim().split(".")[1];
item["item"].authors.push(author);
}
else if (authors[j].trim().split(" ").length == 2){
author["firstName"] = authors[j].trim().split(" ")[0];
author["lastName"] = authors[j].trim().split(" ")[1];
item["item"].authors.push(author);
}
else if (authors[j].trim().split(" ").length == 3) {
author["firstName"] = authors[j].trim().split(" ")[0];
author["lastName"] = authors[j].trim().split(" ")[2];
item["item"].authors.push(author);
}
}
item["item"].imageLink = jsonOutput[i]["Path to demo image"]
if (jsonOutput[i].Keywords != undefined){
item["item"].keywords = jsonOutput[i].Keywords.split(",");
}
else {
item["item"].keywords = jsonOutput[i].Keywords;
}
item["item"].journal.name = jsonOutput[i].Journal;
item["item"].journal.volume = jsonOutput[i].Volume;
item["item"].journal.year = jsonOutput[i].Year;
item["item"].journal.pages = jsonOutput[i].Pages;
item["item"].DOI = jsonOutput[i].DOI;
item["links"].pdf = jsonOutput[i].URL;
item["links"].url = jsonOutput[i].URL;
item["links"].demo = jsonOutput[i].URL;
jsonContent.push(item);
}
console.log(jsonContent);
}
xmlHttpRequest.send();
//
// ending of xlsx to json coversion
//
$(document).ready(function(){
$.getJSON("./content/content.json", function(result){
stuff = result;
......@@ -177,4 +278,4 @@ input.addEventListener("keyup", function(event) {
document.getElementById("search-button_paper").click();
}
});
\ No newline at end of file
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment