Last active
October 25, 2023 09:12
-
-
Save jchome/13bc20729c55b3599b8d267495ca1b96 to your computer and use it in GitHub Desktop.
Load Excel file in web page and request as a database
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
$(document).ready(function () { | |
loadData().then((database) => { | |
console.log(database["onglet_1"]); | |
var onglet = TAFFY(database["onglet_1"]); | |
var titre = onglet({id: "1"}).first()["titre"]; | |
$('#main').html(titre); | |
}); | |
}); | |
function loadData() { | |
resultDict = {}; | |
return new Promise(function(resolve){ | |
var reader = new FileReader(); | |
reader.onload = function () { | |
var fileData = reader.result; | |
var wb = XLSX.read(fileData, { type: 'binary' }); | |
wb.SheetNames.forEach(function (sheetName) { | |
var rowObj = XLSX.utils.sheet_to_row_object_array(wb.Sheets[sheetName]); | |
var jsonObj = JSON.stringify(rowObj); | |
resultDict[sheetName] = jsonObj; | |
}) | |
resolve(resultDict); | |
}; | |
var request = new XMLHttpRequest(); | |
request.open('GET', 'http://localhost:8000/data.xlsx', true); | |
request.responseType = 'blob'; | |
request.onload = function() { | |
reader.readAsBinaryString(request.response); | |
}; | |
request.send(); | |
}); | |
} | |
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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Load Excel file</title> | |
<!-- xlsx --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.8/xlsx.full.min.js"></script> | |
<!-- https://taffydb.com/ --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/taffydb/2.7.3/taffy-min.js" integrity="sha512-EERhZysIK3VRw5B2C7KJxZZvr7pp1Zp4LvE5MOLLvVdPfp/+aZtM568RrSNaMGyMSOQS/lIaOvyThliQ0y3p2g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> | |
<script src="loadExcelAsDatabase-main.js"></script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment