none
Office.BindingType.Table when using addFromNamedItemAsync in Word RRS feed

  • Question

  • I'm having trouble binding to a table in Word 2013. "Understanding the Javascript API for Office" says that I can use one of the three "add" methods of the Binding object. But the msdn documentation for addFromNamedItemAsync (which I need to use) says you can only bind to a rich text box.

    When I try to bind to the rich text box (with a table inside) using the binding type of "Table" sync status error returns: " The specified binding type is not compatible with the supplied named item."

    How do you bind to an existing table or how do you place a table in a specific location in Word using .addFromNamedItemAsync? I do not want to use .addFromSelectionAsync or .addFromPromptAsync because they're not feasible for my solution. I also noticed that you can't name a table in Word like you can in Excel (in the Design section). What am I missing?

     Office.context.document.bindings.addFromNamedItemAsync("Locations", Office.BindingType.Table, { id: 'locations' }, function (result) {
                    if (result.status === Office.AsyncResultStatus.Succeeded) {
                        
                    \\Do Stuff
                            });
                    } else if (result.status === Office.AsyncResultStatus.Failed){
                        write(" binding failed ");
                        write(" addFromNamedItemAsync Error: " + result.error.message);
                    }

    Thursday, July 24, 2014 8:48 PM

Answers

  • Hi Mallahz,

    >> When I try to bind to the rich text box (with a table inside) using the binding type of "Table" sync status error returns: " The specified binding type is not compatible with the supplied named item."<<

    When we use addFromNamedItemAsync to bind a Rich Text content control, we can only use Office.BindingType.Text. Here is a sample for your reference:

    function bindContentControl() {
    
        Office.context.document.bindings.addFromNamedItemAsync('FirstName', 
    
            Office.BindingType.Text, {id:'firstName'},
    
            function (result) {
    
                if (result.status === Office.AsyncResultStatus.Succeeded) {
    
                    write('Control bound. Binding.id: '
    
                        + result.value.id + ' Binding.type: ' + result.value.type);
    
                } else {
    
                    write('Error:', result.error.message);
    
                }
    
        });
    
    }
    
    // Function that writes to a div with id='message' on the page.
    
    function write(message){
    
        document.getElementById('message').innerText += message; 
    
    }
    

    You can get more detail about data binding from link below:
    Binding to regions in a document or spreadsheet

    >> How do you bind to an existing table or how do you place a table in a specific location in Word using .addFromNamedItemAsync?<<

    As the statement of addFromNamedItemAsync, we can't bind to content controls other than the Rich Text content control.

    If you want to it support other controls or table, I suggest you submitting a feedback from here.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 25, 2014 10:53 AM
    Moderator