Below is an explanation of how to load a xlsx file from a server. For uploading, a different code snippet will be needed.
OPTION 1: To achieve this using the Alasql library, follow these steps:
Refer to files: 15utility.js and 84from.js for reference
readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// Perform operations on the parsed xlsx data
});
// Procedure for reading Binary files
// path - file path
// asy - true for async / false for sync
var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};
OPTION 2: Alternatively, you can directly use the Alasql library, which might offer a simpler solution.
alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
[],function(data) {
console.log(res);
});
View examples here (simple Excel reading demo) or here (d3.js demo from Excel).