-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
<script lang="javascript" src="C:/Users/003347/Desktop/xlsx.js"></script>
<script lang="javascript" src="C:/Users/003347/Desktop/jszip-load.js"></script>
<script lang="javascript" src="C:/Users/003347/Desktop/jszip-inflate.js"></script>
<script lang="javascript" src="C:/Users/003347/Desktop/jszip-deflate.js"></script>
function getXLSX(readFile) {
var reader = new FileReader();
// Read file into memory as UTF-16
reader.readAsArrayBuffer(readFile);
// Handle progress, success, and errors
reader.onload = loaded;
}
function loaded(evt) {
var data = evt.target.result;
//var xlsx = XLSX.read(data, {type: 'binary'});
var arr = String.fromCharCode.apply(null, new Uint8Array(data));
var xlsx = XLSX.read(btoa(arr), {type: 'base64'});
process_xlsx(xlsx);
}
function process_xlsx(xlsx) {
var output = "";
output = to_csv(xlsx);
if(out.innerText === undefined) out.textContent = output;
else out.innerText = output;
}
function to_csv(workbook) {
var result = [];
workbook.SheetNames.forEach(function(sheetName) {
var rObjArr = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
if(rObjArr.length > 0){
result.push("SHEET: " + sheetName);
result.push("");
result.push(rObjArr);
}
});
return result.join("\n");
}
while reading with 'readAsBinaryString' xlsx file that consists of numbers i got "Uncaught TypeError: Cannot call method 'getTypeOf' of undefined"
when reading with 'readAsArrayBuffer' this time i got 'Uncaught TypeError: Cannot call method 'decode' of undefined '.Could you please help me what should we import and how should code be whille reading XLSX?i try many version of this link http://www.javascriptoo.com/js-xlsx but doesn't work