Search code examples
exceloffice-jsoffice365-apps

Office.js Excel add-in named binding does not works if we have a hyphen(-) in the sheet name


I am using this the following code to bind to a column in excel using Excel office addin.

var myBindings = Office.context.document.bindings;
var myAddress = "Sheet1!A1:B10";
myBindings.addFromNamedItemAsync(myAddress, "matrix", {id:"myBind"}, 
function(result){});

This works fine, but if the sheet name contains a hypen(-) the same code fails with the message "The named item does not exist."

for instance following code fails.

var myBindings = Office.context.document.bindings;
var myAddress = "Sheet1-1!A1:B10";
myBindings.addFromNamedItemAsync(myAddress, "matrix", {id:"myBind"}, 
function(result){});

Please let me if this is bug in the platform or I am doing something wrong here.


Solution

  • Updating the answer as it works,

    var myAddress = "'Sheet1-1'!A1:B10";

    When the sheet name contains a space or special characters, the '' has to be used