Skip to content Skip to sidebar Skip to footer

Xlsx Parser For Parsing Excel

I am trying to parse xlsx file and save as a table (Along the lines of Excel to JSON javascript code? which is working fine for xls files). However, I am unable to convert to json

Solution 1:

use this code : note: use jszip.js and xlsx.js library

reader.onload = function(evt) {
  debugger;
  var data = evt.target.result;
  //var xlsx = XLSX.read(data, {type: 'binary'});var arr = String.fromCharCode.apply(null, newUint8Array(data));
  var xlsx = XLSX.read(btoa(arr), {
    type: 'base64'
  });
  result = xlsx.Strings;
  result = {};
  xlsx.SheetNames.forEach(function(sheetName) {
    var rObjArr = XLSX.utils.sheet_to_row_object_array(xlsx.Sheets[sheetName]);
    if (rObjArr.length > 0) {
      result[sheetName] = rObjArr;
    }
  });
  return result;
 // that.b64toBlob(xlsx, "binary");
};
reader.readAsArrayBuffer(file);

use readAsArrayBuffer method which will support on all browser.

Post a Comment for "Xlsx Parser For Parsing Excel"