getExpression() from a custom name is undefined

Posted by: diegoar27 on 6 December 2017, 10:43 am EST

  • Posted 6 December 2017, 10:43 am EST

    Hi!

    I’m having an issue when I try create a custom name using refers like this “Sheet1!”. When I try get the expression of the custom name to get the value, that expression is undefined.

    Note:

    this.workbook = new GC.Spread.Sheets.Workbook(

    document.getElementById(containerId),

    spreadOptions

    );

    Steps to reproduce it:

    1. create a custom name

      this.workbook.addCustomName(‘test1’, “‘Sheet1!’!$J$8”, 2, 2)

    Result: it is working ok, I can see my custom name created over my spreadsheet.

    1. I want to get the value of that custom name, to do that I’m doing:

      const customName = this.workbook.getCustomName(‘test1’);

      if(customName) {

      const expression = customName.getExpression();

      const formula = GC.Spread.Sheets.CalcEngine.expressionToFormula(this.workbook, expression);

      (…)

      }

    Result: the expression is undefined, and I’m only getting that error when I create custom names and the references has a sheet name with especial characters.

    Do you have some work around to fix that?

    Thanks in advance!

  • Posted 7 December 2017, 11:37 am EST

    Hello,

    It is working fine at my end, I used the code below:

    
    <script type="text/javascript">
            var spread, activeSheet;
          
            window.onload = function () {
                spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
                activeSheet = spread.getActiveSheet();
                activeSheet.setValue(0, 0, 1);
                activeSheet.setValue(0, 1, 2);
                activeSheet.setValue(0, 2, 3);
                spread.addCustomName("customName1", "'Sheet1!'!$J$8", 0, 0);
                activeSheet.setFormula(1, 0, "customName1");
    
               
            }
            function GetCustomName() {
                var cname = spread.getCustomName("customName1");
                if (cname instanceof GC.Spread.Sheets.NameInfo) {
                    //get CustomName
                    var name = cname.getName();
                    //get Expression
                    var expression = cname.getExpression();
                    //get Expression String
                    var expStr = GC.Spread.Sheets.CalcEngine.expressionToFormula(activeSheet, expression, 0, 0);
                    alert("Name:" + name + ";Expression: =" + expStr);
                }
    
            }
        </script>
    
    

    Please refer to the attached image and html page.

    Thanks,

    Deepak SharmaSpreadJSGetExpression.zip

  • Posted 18 December 2017, 3:24 pm EST

    Hi @deepak

    I tried step by step as you wrote on the last post and I’m getting as formula “Sheet1!!$J$8”

    What spreadjs version are you using? I’m using the version 10.2.0

    Thanks!

  • Posted 19 December 2017, 9:49 am EST

    Hello,

    I have used SpreadJS v10.3.2. You can download the same from here:

    https://cdn.grapecity.com/SpreadCOM/EN_SPREAD8_RA_8.0.28.2017.0503.0.zip

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels