Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
240
Speed of IgxExcelCoreModule Workbook.Load
posted

We have an issue regarding the IgxExcelCoreModule's speed in our project.  For our purposes, we need to read in the names of each sheet within the workbook and then the headers of each sheet.  The following code is what we used to achieve that functionality:

if (event.target.files.length > 0) {
      this.importFile = event.target.files[0];

      //// Infragistics
      this.headersByWorksheetList = [];
      this.availableWorksheetList = [];

      Workbook.load(this.importFile, null,
        (workbook) => {
          console.log("load")
          // Access the worksheets
          for (let i = 0; i < workbook.worksheets().count; i++) {
            const worksheet = workbook.worksheets(i);
            this.availableWorksheetList.push(worksheet.name);
            const headers = [];
            const firstRow = worksheet.rows(0);
            for (let cellIndex = 0; cellIndex < firstRow.cells().count; cellIndex++) {
              headers.push(firstRow.cells(cellIndex).value)
            }
            this.headersByWorksheetList.push(new HeadersByWorkSheet(worksheet.name, headers));
            // console.log(`Worksheet ${i + 1}: ${worksheet.name}`);
          }

          console.log(this.headersByWorksheetList);

        }, (error) => {
          // Error callback: Handle any errors
          console.error('Error loading workbook:', error);
      });
      }

However, doing this with a reasonably small workbook (1700KB) takes ten plus seconds to load and with a larger one (21MB) it took around 4-5 mins, which is something we would potentially need to do.  This seems very unwieldy considering the simplicity of the functionality required. And this is just to get a response from the Workbook.load function, not even the loop within it - this is the time it takes to print console.log("load").

By contrast, using the XLSX library here sheetjs/README.md at master - sheetjs - SheetJS I tried the following code to perform the same action:

if (event.target.files.length > 0) {
      this.importFile = event.target.files[0];

      

      ////// XLSX
      const file: File = event.target.files[0];
      this.importFile = file;

      const reader = new FileReader();

      reader.onload = (e: any) => {
        /* Read the binary string */
        const bstr = e.target.result;
        const workbook = XLSX.read(bstr, { type: 'binary' });

        // this.worksheetList = workbook.SheetNames;
        this.availableWorksheetList = workbook.SheetNames;

        this.activeHeadersList = [];
        this.headersByWorksheetList = [];
        this.resetAllFields();

        workbook.SheetNames.forEach(sheetName => {
          const currentWorksheet = workbook.Sheets[sheetName];
          const data = XLSX.utils.sheet_to_json(currentWorksheet, { header: 1 });

          // Check column headers
          if (data.length > 0) {
            // this.worksheetList = [...this.worksheetList, ...workbook.SheetNames];

            this.headersByWorksheetList.push(new HeadersByWorkSheet(sheetName, data[0] as string[])); // First row contains headers
          }
        });
      }

      reader.readAsArrayBuffer(file);
    }

This one performed the same action in under a second, which is much more reasonable.  I wondered if there was something we could do to potentially replicate these speeds using the Infragistics Excel library?

Thanks!