-1

I am pretty new to Office Add-ins with Javascript API, currently i am coding for Excel 2013. I want to get the Cell address for a given Excel Named Range. i have the below code which will give me Columns and Rows count, but do not have an option to get the Start Col number or Row number. Please help

function GetRangeAddress() {
        Office.context.document.bindings.addFromNamedItemAsync("myRange", "matrix", { id: 'myMatrix' }, function (result) {
            if (result.status == 'succeeded') {
                write('Columns: ' + result.value.columnCount + '  Rows: ' + result.value.rowCount );
            }
            else
                write('Error: ' + result.error.message);
        });

    }
SSK
  • 783
  • 3
  • 18
  • 42

1 Answers1

0

The return object of Office.context.document.bindings.addFromNamedItemAsync is Binding object. There is no property of method we can get the address from the binding object.

However the new version of API which support for Excel 2016, we can get the address of name range directly. Here is an sample for your reference:

function getAddress() {
    Excel.run(function (ctx) {
        var names = ctx.workbook.names;
        var namedItem = names.getItem('MyRange');
        var range = namedItem.getRange();
        range.load('address')

        return ctx.sync().then(function () {
            console.log(range.address);
        });
    }).catch(function (error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
    });

}

And you can get more detail about the new API from link below:

https://msdn.microsoft.com/en-us/library/office/mt616490.aspx

And if you have any idea of feedback about Office add-in, you can try to submit the feedback from link below:

https://officespdev.uservoice.com/

Fei Xue
  • 14,369
  • 1
  • 19
  • 27