none
How to get Address from a given Excel Named Range in office.js? RRS feed

  • Question

  • 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);
            });
    
        }

    Wednesday, March 2, 2016 5:53 AM

Answers

  • Hi haissk,

    >> I want to get the Cell address for a given Excel Named Range.

    I suggest you use range.address to get address of Named Range. Here is a simple code:

    function getExcelRangeAddress() {
        Excel.run(function (ctx) {
            var names = ctx.workbook.names;
            var range = names.getItem('MyRange').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));
            }
        });
    }

    You could refer the link below for more information.
    # NamedItem object (JavaScript API for Excel)
    https://msdn.microsoft.com/en-us/library/office/mt598653.aspx

    Best Regards,

    Edward


    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.


    Thursday, March 3, 2016 9:24 AM