Amitava Karan
Amitava Karan

Reputation: 677

hide rows in excel workbook using office.js

We are building an excel addin using office.js. We want to hide a range of rows. I checked the Excel Javascript API Documentation. I did not find any solution for that.

Could someone please help on this.

Upvotes: 1

Views: 2606

Answers (2)

Rick Kirkham
Rick Kirkham

Reputation: 9684

Kim Brandi's answer is good. If you are working with tables another option that might be useful depending on your scenario is to hide rows by filtering. See the Table and TableColumn reference topics.

Upvotes: 0

Kim Brandl
Kim Brandl

Reputation: 13480

Using Office.js, you can programmatically hide and unhide rows by updating the rowHidden property on the range object. The following example shows how to hide rows 2-5 in Sheet1.

Excel.run(function (context) {

    // Hide rows 2-5 in 'Sheet1'
    var range = context.workbook.worksheets.getItem("Sheet1").getRange("2:5");
    range.rowHidden = true;

    return context.sync()
        .then(function() {
            console.log("Rows 2-5 have been hidden.");
        });
}).catch(function (error) {
        OfficeHelpers.UI.notify(error);
        OfficeHelpers.Utilities.log(error);
});

To unhide rows in a range, set the rowHidden property to false. You can find documentation of the rowHidden property (and the columnHidden property, for hiding/unhiding columns) here in the Excel API Reference docs: https://dev.office.com/reference/add-ins/excel/range.

Upvotes: 2

Related Questions