TypeError: Cannot read properties of undefined getName

Posted by: sidney.silva on 20 January 2023, 7:58 am EST

    • Post Options:
    • Link

    Posted 20 January 2023, 7:58 am EST - Updated 20 January 2023, 8:06 am EST

    Hi,

    I’m using spreadjs:

    @grapecity/spread-sheets": “^15.1.4”

    @grapecity/spread-sheets-angular”: “^15.1.4”

    When trying to import a .xlsx spreadsheet that contains external links, the following error occurs:

    core.js:4002 ERROR TypeError: Cannot read properties of undefined (reading 'option')
        at b.getName (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at b.getExternalSourceToken (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at Q (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at N (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at b.unparse (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at a.Cma (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at a.unparse (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at a.unparse (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at a.<anonymous> (gc.spread.sheets.designer.all.min.js:formatted:241604)
        at Function.H [as each] (gc.spread.sheets.designer.all.min.js:formatted:241604)

    How can I fix this problem?

  • Posted 23 January 2023, 3:32 pm EST

    Hi Sidney,

    Create a GC.Spread.Excel.IO() class object and use the excelIO.open() method to import an.xlsx (excel) file. This method converts a file or blob object to a json object. This json object can be loaded into spread using the spread.fromJSON(json) method.

    Kindly refer to the sample attached below which explains the same in angular.

    Doc References:

    import/export demo: https://www.grapecity.com/spreadjs/demos/features/workbook/excel-import-export#demo_source_name

    GC.Spread.Excel.IO() class: https://www.grapecity.com/spreadjs/api/v15/excelio/classes/Excel.IO-1

    excelIO.open(): https://www.grapecity.com/spreadjs/api/v15/excelio/classes/Excel.IO-1#open

    spread.fromJSON(): https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#fromjson

    If you continue to have problems, please share a small sample of the problem. You could also modify the above sample and send it to us to replicate the problem.

    Regards,

    Ankit

    angular-sample.zip

  • Posted 24 January 2023, 2:24 am EST - Updated 24 January 2023, 2:30 am EST

    Hi Ankit,

    This is the code snippet that I import:

    excelIo.open(
          excelFile,
          function (json: any) {
            const existingJSON = _workbook.toJSON();
            _mergeJSON(existingJSON, [json], estilo, formula);
            _workbook.fromJSON(existingJSON, {
              frozenColumnsAsRowHeaders: coluna,
              frozenRowsAsColumnHeaders: linha,
              doNotRecalculateAfterLoad: calcularFormula,
            });
          },
          function (err) {
            _alertService.showErrorAlert(err.errorMessage);
            this.loading = false;
          } );

    There is no error when importing, but when I click on any element on the screen, the error below occurs and all the tabs disappear.

    See in the image below:

  • Posted 24 January 2023, 5:30 pm EST

    Hi Sidney,

    There could be an issue with the _mergeJSON() method you’re using to combine the json of two spreads. Spreadjs does not render content after you click on a cell because of this.

    We’ve included a sample that combines the json of the current spread and the loaded excel file before loading the merged json file into the spread with the spread.fromJSON() method.

    Please try merging using the approach outlined in the attached sample. If the problem persists for you, please share a small sample with us so that we can investigate it and assist you accordingly.

    You could also open a new case on our private portal if your sample contains sensitive information: https://www.grapecity.com/my-account/my-support

    Regards,

    Ankit

    angular-sample (1).zip

  • Posted 3 February 2023, 3:42 am EST

    Hi, I work with Sidney on this project.

    I believe the problem is in json’s names property.

    this code snippet shows how we merge from the imported table

    if (origemJson.names) {
            if (destinoJson.names) {
              destinoJson.names.push(...origemJson.names);
            } else {
              destinoJson.names = origemJson.names;
            }
          }

    I just copy the names property to the source.

  • Posted 3 February 2023, 4:36 am EST

    I think the problem is in the list of names. Is there any way to filter out the incorrect ones?names.zip

  • Posted 6 February 2023, 4:39 am EST

    Hello Pedro,

    We tested the code snippet you provided to see if it causes the issue of spread not rendering after loading merged json of two or more spreads. However, it doesn’t cause this error because it simply changes the custom names on the spread level and may cause a #NAME? error if the custom name referenced in the sheet is not available on the spread level after loading the merged json.

    Please provide us with a sample that replicates the problem so that we can assist you appropriately.

    Here’s an example that explains the concept.

    https://codesandbox.io/s/solution-forked-6o4j00?file=/src/index.js as an example

    Regards,

    Ankit

  • Posted 19 April 2024, 4:01 am EST

    I updated to v17 and the issue resolved. Thank you for your help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels