How to handle IfError in Angular code for Spread JS 14?

Posted by: pooja.bansal on 13 April 2021, 5:53 pm EST

    • Post Options:
    • Link

    Posted 13 April 2021, 5:53 pm EST

    Hi,

    We are getting error in the below line of code -

    var cellValue = activeSheet.getValue(row, i);

    It is returning {_error: “#DIV/0!”, _code: 7} value.

    In case of these kind of errors we would require to replace “cellValue” variable with null in the code.

    Kindly suggest how we can do this?

    Regards

    Pooja Bansal

  • Posted 14 April 2021, 10:12 pm EST

    Hi Pooja,

    For this, You need to override the getValue method. Please refer to the following code snippet and let us if you face any issues.

    
    let old = GC.Spread.Sheets.Worksheet.prototype.getValue;
    GC.Spread.Sheets.Worksheet.prototype.getValue = function (row, col) {
      let oldvalue = old.apply(this, arguments);
      if (oldvalue instanceof Object && oldvalue._error === "#DIV/0!")
        return "Error";
      else return oldvalue;
    };
    var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {
      scrollByPixel: true,
      scrollPixel: 5,
    });
    
    

    getValue: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~getValue.html

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels