dimanche 18 juillet 2021

How to lock multiple cells in range group, Excel - Web AddIns Office.js API

I have two cells merged into one in Excel.

Also, I have given the range name to it.

enter image description here

In code (js), I am trying to lock the cells in the group:

                Excel.run(function (ctx) {

                var s = ctx.workbook.worksheets.getActiveWorksheet();
                                                        
                return ctx.sync()
                    .then(() => {

                        var cell = s.getRange("dateFrom");
                        cell.format.protection.locked = true;

                        ctx.sync();
                    });
            }).catch(errorHandler);

The issue seems to be that only the first cell from left in this group is getting locked and the second does not. As a result of this, the grouped/merged cell is set to locked=null

enter image description here

Any idea how to get over this problem?

It seems to be working fine when using the exact range definition (not a range names) - "B5:C5".

Regards, M.




Aucun commentaire:

Enregistrer un commentaire