none
Last Used Cell RRS feed

  • Question

  • How to get the last used cell in a specific column in excel via JS API?


    • Edited by Moisk Monday, March 14, 2016 2:05 AM
    Monday, March 14, 2016 2:04 AM

Answers

  • If you were developing with Office 2016, we can get the last used cell of a specific column via code below:

     function getLastCellinColumn() {
            var sheetName="sheet1"
            var columnAddress = "B:B";
            Excel.run(function (ctx) {
                var ws = ctx.workbook.worksheets.getItem(sheetName);
                var range = ws.getRange(columnAddress);
                var lastCell=range.getUsedRange().getLastCell();
                lastCell.load('address')
    
                return ctx.sync().then(function () {
                    console.log(lastCell.address);
                });
            }).catch(function (error) {
                console.log("Error: " + error);
                if (error instanceof OfficeExtension.Error) {
                    console.log("Debug info: " + JSON.stringify(error.debugInfo));
                }
            });
    
    
        }

    And if you want it also support for other Office version, you can try to submit the feedback from link below:
    Customer Feedback for the Office Developer Platform

    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.

    • Marked as answer by Moisk Friday, March 18, 2016 1:59 AM
    Tuesday, March 15, 2016 11:13 AM
    Moderator

All replies

  • If you were developing with Office 2016, we can get the last used cell of a specific column via code below:

     function getLastCellinColumn() {
            var sheetName="sheet1"
            var columnAddress = "B:B";
            Excel.run(function (ctx) {
                var ws = ctx.workbook.worksheets.getItem(sheetName);
                var range = ws.getRange(columnAddress);
                var lastCell=range.getUsedRange().getLastCell();
                lastCell.load('address')
    
                return ctx.sync().then(function () {
                    console.log(lastCell.address);
                });
            }).catch(function (error) {
                console.log("Error: " + error);
                if (error instanceof OfficeExtension.Error) {
                    console.log("Debug info: " + JSON.stringify(error.debugInfo));
                }
            });
    
    
        }

    And if you want it also support for other Office version, you can try to submit the feedback from link below:
    Customer Feedback for the Office Developer Platform

    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.

    • Marked as answer by Moisk Friday, March 18, 2016 1:59 AM
    Tuesday, March 15, 2016 11:13 AM
    Moderator
  • Thanks so Much
    Friday, March 18, 2016 1:59 AM