function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jian Ming YuJian Ming Yu 

Lightning web component using xlsx libraries

I am trying to use the XLSX-JS (which is the thrid party library ) to load execl data into salesforce, I have uplaod the xlsx.js as static resource into salesforce platform and use loadScript to load the js code into webpage, but when I call method I got a XLSX is undefined message. Anyone can advise me how to referece XLSX 
import { LightningElement, track } from "lwc";
import { loadScript } from "lightning/platformResourceLoader";
import xlsx from "@salesforce/resourceUrl/xlsx";

xlsxInitialized = false;
  renderedCallback() {
    if (this.xlsxInitialized) {
    this.xlsxInitialized = true;
    loadScript(this, xlsx + '/xlsx/xlsx.core.min.js')
            .then(() => {
            .catch(error => {
                this.error = error;
  handleFileChange(e) {
    var files =;
    var file = files[0];
    this.readWorkbookFromLocalFile(file, workbook => {
      var sheetNames = workbook.SheetNames; // 工作表名称集合
      var worksheet = workbook.Sheets[sheetNames[0]]; // 这里我们只读取第一张sheet

  readWorkbookFromLocalFile(file, callback) {
    var reader = new FileReader();
    reader.onload = e => {
      var data =;
      var workbook =, { type: "binary" });
      console.log("workbook :" + workbook);
      if (callback) callback(workbook);
Siva Nekkalapudi 5Siva Nekkalapudi 5
Did you by any chance solve this issue? If so can you help me with the same. 
Hi @Jian Ming Yu ,  Could you please help me with the same issue.
I was able to solve the issue not only I could read the file but also I saved each row as record also.

I had to update the xlsx library file. only at line number 5. 
shivangi gulati 7shivangi gulati 7

@S@uravv: can u please share the updated code after you fix the error? I am facing th same error

How you passed the xlxs data to apex? can u please share the pseudo code of apex class?


update your library (line # 5 & 6)as below.
var XLSX = {};
window.XLSX = XLSX;

I am assuming that you are creating a LWC.

after loading the static resource..
Do handling the file select:
handleFileSelect(event) { 
        var files =; 
        var file=files[0];
        this.ExcelToJSON (file);
        var reader=new FileReader();
        reader.onload = event => {
            var, {
                type: 'binary'
            var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets["Your sheet name"]);
            var data = JSON.stringify(XL_row_object);
        reader.onerror = function(ex) {
                new ShowToastEvent({
                    title: 'Error while reding the file',
                    message: ex.message,
                    variant: 'error',