XLSX is not defined

if i used XLSX plugin in my javascript code in “run javascript” tool workflow, then it throws the error.
XLSX is not defined.

Should I have to add any import statements for accessing XLSX library. If yes, then where and how i have to do this.

Here is the javascript code :

const uploaderDiv = document.getElementById('uploader');
const secondElementInsideUploader = uploaderDiv.children[1];
var files = secondElementInsideUploader.files;
const file = new Blob([secondElementInsideUploader.files[0]]);
 var reader = new FileReader();
 reader.readAsBinaryString(file);
 reader.onload = function (e) {
 var data = e.target.result;
 var workbook = XLSX.read(data, {
          type: "binary",
 });
  var result = {};
  var firstSheetName = workbook.SheetNames[0];
  var jsonData = XLSX.utils.sheet_to_json(
          workbook.Sheets[firstSheetName]
  );
        alert(JSON.stringify(jsonData));
};

Add this to your page header or app html.

</script src=“https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.core.min.js” integrity=“sha512-UhlYw//T419BPq/emC5xSZzkjjreRfN3426517rfsg/XIEC02ggQBb680V0VvP+zaDZ78zqse3rqnnI5EJ6rxA==” crossorigin=“anonymous” referrerpolicy=“no-referrer”></script/>

obviously fix the script tag (won’t show if I removed the slashes).

Yes, I’ve already execute this solution, but it doesn’t work. It always shows the “XLSX not defined” error.

Is your sole goal to turn a spreadsheet into JSON?

If you can give me your over-all goal, I may be able to find you a better solution.

Actually yes, But my actual goat is to save the fields of spreadsheet in database.
I’ve used the workflow “Download data as CSV”, but it only accept csv files.
that’s why i’ve decided to use javascript for this. Is this right approach?

This topic was automatically closed after 69 days. New replies are no longer allowed.