Created
May 28, 2014 17:15
-
-
Save SheetJSDev/80c3a7cd04cdefdfaa86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* generate CSV output for every sheet */ | |
function to_csv(workbook) { | |
var result = []; | |
workbook.SheetNames.forEach(function(sheetName) { | |
var csv = XLSX.utils.make_csv(workbook.Sheets[sheetName]); | |
if(csv.length > 0){ | |
result.push("SHEET: " + sheetName); | |
result.push(""); | |
result.push(csv); | |
} | |
}); | |
return result.join("\n"); | |
} | |
/* Write to the page (`out` is a PRE element on the page) */ | |
function process_wb(wb) { | |
var output = to_csv(wb); | |
if(out.innerText === undefined) out.textContent = output; | |
else out.innerText = output; | |
} | |
/* set up XMLHttpRequest */ | |
var url = "test_files/formula_stress_test_ajax.xlsx"; | |
var oReq = new XMLHttpRequest(); | |
oReq.open("GET", url, true); | |
oReq.responseType = "arraybuffer"; | |
oReq.onload = function(e) { | |
var arraybuffer = oReq.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 wb = XLSX.read(bstr, {type:"binary"}); | |
process_wb(wb); | |
} | |
oReq.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment